[libcxx-commits] [libcxx] [libc++] Implement P2442R1 `std::views::chunk` (PR #171234)

via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jun 21 08:54:45 PDT 2026


================
@@ -0,0 +1,108 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++23
+
+// <ranges>
+
+//   V models only input_range
+//     friend constexpr bool operator==(const outer_iterator& x, default_sentinel_t);
+//     friend constexpr bool operator==(const inner_iterator& x, default_sentinel_t);
+
+//   V models forward_range
+//     friend constexpr bool operator==(const iterator& x, const iterator& y);
+//     friend constexpr bool operator==(const iterator& x, default_sentinel_t);
+//     friend constexpr bool operator<(const iterator& x, const iterator& y)
+//       requires random_access_range<Base>;
+//     friend constexpr bool operator>(const iterator& x, const iterator& y)
+//       requires random_access_range<Base>;
+//     friend constexpr bool operator<=(const iterator& x, const iterator& y)
+//       requires random_access_range<Base>;
+//     friend constexpr bool operator>=(const iterator& x, const iterator& y)
+//       requires random_access_range<Base>;
+//     friend constexpr auto operator<=>(const iterator& x, const iterator& y)
+//       requires random_access_range<Base> &&
+//                three_way_comparable<iterator_t<Base>>;
+
+#include <cassert>
+#include <compare>
+#include <iterator>
+#include <ranges>
+#include <vector>
+
+#include "test_range.h"
+#include "../types.h"
+
+constexpr bool test() {
+  std::vector<int> vector                                                  = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
+  std::ranges::chunk_view<std::ranges::ref_view<std::vector<int>>> chunked = vector | std::views::chunk(3);
+  std::ranges::chunk_view<input_span<int>> input_chunked = input_span<int>(vector) | std::views::chunk(3);
+
----------------
huixie90 wrote:

for this particular test, I think we need to test the branch where 

__parent_->__remainder_ == 0;

https://github.com/llvm/llvm-project/pull/171234


More information about the libcxx-commits mailing list