[libcxx-commits] [libcxx] [libc++] LWG4012: common_view::begin/end are missing the simple-view check (PR #153674)
Hristo Hristov via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Aug 19 10:52:10 PDT 2025
================
@@ -73,21 +75,64 @@ static_assert(std::ranges::sized_range<SizedRandomAccessView>);
struct CommonView : std::ranges::view_base {
int* begin_;
int* end_;
- constexpr explicit CommonView(int* b, int* e) : begin_(b), end_(e) { }
- constexpr int *begin() const { return begin_; }
- constexpr int *end() const { return end_; }
+ constexpr explicit CommonView(int* b, int* e) : begin_(b), end_(e) {}
+ constexpr int* begin() const { return begin_; }
+ constexpr int* end() const { return end_; }
};
static_assert(std::ranges::view<CommonView>);
static_assert(std::ranges::common_range<CommonView>);
struct NonCommonView : std::ranges::view_base {
int* begin_;
int* end_;
- constexpr explicit NonCommonView(int* b, int* e) : begin_(b), end_(e) { }
- constexpr int *begin() const { return begin_; }
+ constexpr explicit NonCommonView(int* b, int* e) : begin_(b), end_(e) {}
+ constexpr int* begin() const { return begin_; }
constexpr auto end() const { return sentinel_wrapper<int*>(end_); }
};
-static_assert( std::ranges::view<NonCommonView>);
+static_assert(std::ranges::view<NonCommonView>);
static_assert(!std::ranges::common_range<NonCommonView>);
+template <class T>
+concept HasConstBegin = requires(const T& ct) { ct.begin(); };
+
+template <class T>
+concept HasBegin = requires(T& t) { t.begin(); };
+
+template <class T>
+concept HasConstAndNonConstBegin = HasConstBegin<T> && requires(T& t, const T& ct) {
+ requires !std::same_as<decltype(t.begin()), decltype(ct.begin())>;
+};
+
+template <class T>
+concept HasOnlyNonConstBegin = HasBegin<T> && !HasConstBegin<T>;
+
+template <class T>
+concept HasOnlyConstBegin = HasConstBegin<T> && !HasConstAndNonConstBegin<T>;
+
+template <bool Simple>
+struct NonCommonBaseView : std::ranges::view_base {
+ int* begin_;
+ int* end_;
+ constexpr explicit NonCommonBaseView(int* b, int* e) : begin_(b), end_(e) {}
+ constexpr auto begin() const { return static_cast<const int*>(begin_); }
+ constexpr auto end() const { return sentinel_wrapper<const int*>(end_); }
+ constexpr int* begin()
+ requires(!Simple)
----------------
H-G-Hristov wrote:
Is this `requires(!Simple)` necessary for this test?
https://github.com/llvm/llvm-project/pull/153674
More information about the libcxx-commits
mailing list