[libcxx-commits] [libcxx] [libc++][ranges][enumerate_view] Fix sentinel converting constructor test (PR #217365)

Hristo Hristov via libcxx-commits libcxx-commits at lists.llvm.org
Wed Aug 19 09:01:21 PDT 2026


================
@@ -28,6 +28,67 @@
 #include "test_iterators.h"
 
 #include "../types.h"
+#include "../../range_adaptor_types.h"
+
+template <class T>
+struct convertible_sentinel_wrapper {
+  explicit convertible_sentinel_wrapper() = default;
+  constexpr convertible_sentinel_wrapper(const T& it) : it_(it) {}
+
+  template <class U>
+    requires std::convertible_to<const U&, T>
+  constexpr convertible_sentinel_wrapper(const convertible_sentinel_wrapper<U>& other) : it_(other.it_) {}
+
+  constexpr friend bool operator==(convertible_sentinel_wrapper const& self, const T& other) {
+    return self.it_ == other;
+  }
+  T it_;
+};
+
+struct NonSimpleNonCommonConvertibleView : IntBufferView {
+  using IntBufferView::IntBufferView;
+
+  constexpr int* begin() { return buffer_; }
+  constexpr const int* begin() const { return buffer_; }
+  constexpr convertible_sentinel_wrapper<int*> end() { return convertible_sentinel_wrapper<int*>(buffer_ + size_); }
+  constexpr convertible_sentinel_wrapper<const int*> end() const {
+    return convertible_sentinel_wrapper<const int*>(buffer_ + size_);
+  }
+};
+
+// convertible_to<sentinel<false>, sentinel<Const>>
+static_assert(std::convertible_to< //
+              std::ranges::sentinel_t<std::ranges::enumerate_view<NonSimpleNonCommonConvertibleView>>,
+              std::ranges::sentinel_t<std::ranges::enumerate_view<NonSimpleNonCommonConvertibleView> const>>);
+
+constexpr void test_SFINAE() {
+  int buffer[3] = {1, 2, 3};
+
+  // Underlying non-const to const not convertible.
+  {
+    std::ranges::enumerate_view v{NonSimpleNonCommonConvertibleView(buffer)};
+    auto sent1 = v.end();
+    auto sent2 = std::as_const(v).end();
----------------
Zingam wrote:

```suggestion
    auto sent = v.end();
    auto const_sent = std::as_const(v).end();
```
Suggestion to rename those for clarity. WDYT?

BTW I use `it` for iterator variables and `st` for sentinel variables in the remaining tests. I think the ranges library uses Iter and Sent but I am not sure it this is just for parameters/types or also for variables.

Or

```suggestion
    auto st= v.end();
    auto const_st= std::as_const(v).end();
```


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


More information about the libcxx-commits mailing list