[libcxx-commits] [libcxx] [libc++][ranges][enumerate_view] Fix sentinel converting constructor test (PR #217365)
Lucas Mellone via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Aug 19 09:04:04 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();
----------------
lknknm wrote:
Let's use the `st` variation, although I used `sent` to conform with some other tests in the suite like the ones from `zip.view` and `adjancent.view`. I personally prefer the `st` and `const_st` variation. Wdyt?
https://github.com/llvm/llvm-project/pull/217365
More information about the libcxx-commits
mailing list