[libcxx-commits] [libcxx] [libc++][ranges][enumerate_view] Update sentinel `equal` test (PR #222331)

Lucas Mellone via libcxx-commits libcxx-commits at lists.llvm.org
Mon Oct 5 08:54:00 PDT 2026


================
@@ -0,0 +1,219 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+// class enumerate_view
+
+// class enumerate_view::sentinel
+
+// template<bool OtherConst>
+//   requires sentinel_for<sentinel_t<Base>, iterator_t<maybe-const<OtherConst, V>>>
+// friend constexpr bool operator==(const iterator<OtherConst>& x, const sentinel& y);
+
+#include <cassert>
+#include <concepts>
+#include <ranges>
+#include <type_traits>
+#include <utility>
+
+#include "../../range_adaptor_types.h"
+#include "../types.h"
+#include "test_iterators.h"
+#include "test_range.h"
+
+using Iterator      = random_access_iterator<int*>;
+using ConstIterator = contiguous_iterator<const int*>;
+
+template <bool Const>
+struct ComparableSentinel {
+  using Iter = std::conditional_t<Const, ConstIterator, Iterator>;
+  Iter iter_;
+
+  explicit ComparableSentinel() = default;
+  constexpr explicit ComparableSentinel(const Iter& it) : iter_(it) {}
+
+  constexpr friend bool operator==(const Iterator& i, const ComparableSentinel& s) { return base(i) == base(s.iter_); }
+
+  constexpr friend bool operator==(const ConstIterator& i, const ComparableSentinel& s) {
+    return base(i) == base(s.iter_);
+  }
+};
+
+struct ComparableView : IntBufferView {
+  using IntBufferView::IntBufferView;
+
+  constexpr auto begin() { return Iterator(buffer_); }
+  constexpr auto begin() const { return ConstIterator(buffer_); }
+  constexpr auto end() { return ComparableSentinel<false>(Iterator(buffer_ + size_)); }
+  constexpr auto end() const { return ComparableSentinel<true>(ConstIterator(buffer_ + size_)); }
+};
+
+struct ConstIncompatibleView : IntBufferView {
+  using IntBufferView::IntBufferView;
+
+  constexpr random_access_iterator<int*> begin() { return random_access_iterator<int*>(buffer_); }
+  constexpr contiguous_iterator<const int*> begin() const { return contiguous_iterator<const int*>(buffer_); }
+  constexpr sentinel_wrapper<random_access_iterator<int*>> end() {
+    return sentinel_wrapper<random_access_iterator<int*>>(random_access_iterator<int*>(buffer_ + size_));
+  }
+  constexpr sentinel_wrapper<contiguous_iterator<const int*>> end() const {
+    return sentinel_wrapper<contiguous_iterator<const int*>>(contiguous_iterator<const int*>(buffer_ + size_));
+  }
+};
+
+constexpr bool test() {
+  int buffer[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
----------------
lknknm wrote:

I have applied this suggestion and changed the other bits that relied on this buffer.

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


More information about the libcxx-commits mailing list