diff --git a/libcxx/test/libcxx/ranges/range.utility.helpers/simple_view.compile.pass.cpp b/libcxx/test/libcxx/ranges/range.utility.helpers/simple_view.compile.pass.cpp --- a/libcxx/test/libcxx/ranges/range.utility.helpers/simple_view.compile.pass.cpp +++ b/libcxx/test/libcxx/ranges/range.utility.helpers/simple_view.compile.pass.cpp @@ -18,29 +18,25 @@ #include "test_iterators.h" struct SimpleView : std::ranges::view_base { - friend int* begin(SimpleView&); - friend int* begin(SimpleView const&); - friend int* end(SimpleView&); - friend int* end(SimpleView const&); + int *begin() const; + int *end() const; }; struct WrongConstView : std::ranges::view_base { - friend int* begin(WrongConstView&); - friend const int* begin(WrongConstView const&); - friend int* end(WrongConstView&); - friend const int* end(WrongConstView const&); + int *begin(); + const int *begin() const; + int *end(); + const int *end() const; }; struct NoConstView : std::ranges::view_base { - friend int* begin(NoConstView&); - friend int* end(NoConstView&); + int *begin(); + int *end(); }; struct DifferentSentinel : std::ranges::view_base { - friend int* begin(DifferentSentinel&); - friend int* begin(DifferentSentinel const&); - friend sentinel_wrapper end(DifferentSentinel&); - friend sentinel_wrapper end(DifferentSentinel const&); + int *begin() const; + sentinel_wrapper end() const; }; static_assert( std::ranges::__simple_view); diff --git a/libcxx/test/std/ranges/range.access/range.prim/data.pass.cpp b/libcxx/test/std/ranges/range.access/range.prim/data.pass.cpp --- a/libcxx/test/std/ranges/range.access/range.prim/data.pass.cpp +++ b/libcxx/test/std/ranges/range.access/range.prim/data.pass.cpp @@ -106,16 +106,16 @@ constexpr ContiguousIter begin() const { return ContiguousIter(buff); } }; - static_assert( std::is_invocable_v); static_assert(!std::is_invocable_v); +static_assert( std::is_invocable_v); +static_assert(!std::is_invocable_v); struct BeginMemberRandomAccess { int buff[8]; random_access_iterator begin() const; }; - static_assert(!std::is_invocable_v); static_assert(!std::is_invocable_v); static_assert(!std::is_invocable_v); @@ -127,11 +127,14 @@ return ContiguousIter(iter.buff); } }; +static_assert( std::is_invocable_v); +static_assert(!std::is_invocable_v); +static_assert( std::is_invocable_v); +static_assert(!std::is_invocable_v); struct BeginFriendRandomAccess { friend random_access_iterator begin(const BeginFriendRandomAccess iter); }; - static_assert(!std::is_invocable_v); static_assert(!std::is_invocable_v); static_assert(!std::is_invocable_v); @@ -141,16 +144,18 @@ ContiguousIter begin() &&; }; - static_assert(!std::is_invocable_v); static_assert(!std::is_invocable_v); struct BeginMemberBorrowingEnabled { constexpr contiguous_iterator begin() { return contiguous_iterator{&globalBuff[1]}; } }; - template<> inline constexpr bool std::ranges::enable_borrowed_range = true; +static_assert( std::is_invocable_v); +static_assert( std::is_invocable_v); +static_assert(!std::is_invocable_v); +static_assert(!std::is_invocable_v); constexpr bool testViaRangesBegin() { int arr[2]; diff --git a/libcxx/test/std/ranges/range.adaptors/range.all/all.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.all/all.pass.cpp --- a/libcxx/test/std/ranges/range.adaptors/range.all/all.pass.cpp +++ b/libcxx/test/std/ranges/range.adaptors/range.all/all.pass.cpp @@ -31,10 +31,8 @@ constexpr explicit View(int start) : start_(start) {} View(View&&) noexcept(IsNoexcept) = default; View& operator=(View&&) noexcept(IsNoexcept) = default; - friend constexpr int* begin(View& view) { return globalBuff + view.start_; } - friend constexpr int* begin(View const& view) { return globalBuff + view.start_; } - friend constexpr int* end(View&) { return globalBuff + 8; } - friend constexpr int* end(View const&) { return globalBuff + 8; } + constexpr int* begin() const { return globalBuff + start_; } + constexpr int* end() const { return globalBuff + 8; } }; static_assert(std::ranges::view>); static_assert(std::ranges::view>); @@ -46,10 +44,8 @@ CopyableView(CopyableView const&) noexcept(IsNoexcept) = default; CopyableView& operator=(CopyableView const&) noexcept(IsNoexcept) = default; constexpr explicit CopyableView(int start) noexcept : start_(start) {} - friend constexpr int* begin(CopyableView& view) { return globalBuff + view.start_; } - friend constexpr int* begin(CopyableView const& view) { return globalBuff + view.start_; } - friend constexpr int* end(CopyableView&) { return globalBuff + 8; } - friend constexpr int* end(CopyableView const&) { return globalBuff + 8; } + constexpr int* begin() const { return globalBuff + start_; } + constexpr int* end() const { return globalBuff + 8; } }; static_assert(std::ranges::view>); static_assert(std::ranges::view>); @@ -57,19 +53,15 @@ struct Range { int start_; constexpr explicit Range(int start) noexcept : start_(start) {} - friend constexpr int* begin(Range const& range) { return globalBuff + range.start_; } - friend constexpr int* begin(Range& range) { return globalBuff + range.start_; } - friend constexpr int* end(Range const&) { return globalBuff + 8; } - friend constexpr int* end(Range&) { return globalBuff + 8; } + constexpr int* begin() const { return globalBuff + start_; } + constexpr int* end() const { return globalBuff + 8; } }; struct BorrowableRange { int start_; constexpr explicit BorrowableRange(int start) noexcept : start_(start) {} - friend constexpr int* begin(BorrowableRange const& range) { return globalBuff + range.start_; } - friend constexpr int* begin(BorrowableRange& range) { return globalBuff + range.start_; } - friend constexpr int* end(BorrowableRange const&) { return globalBuff + 8; } - friend constexpr int* end(BorrowableRange&) { return globalBuff + 8; } + constexpr int* begin() const { return globalBuff + start_; } + constexpr int* end() const { return globalBuff + 8; } }; template<> inline constexpr bool std::ranges::enable_borrowed_range = true; @@ -80,7 +72,6 @@ friend constexpr std::ptrdiff_t operator-(sentinel, random_access_iterator) { return -8; } friend constexpr std::ptrdiff_t operator-(random_access_iterator, sentinel) { return 8; } }; - constexpr random_access_iterator begin() { return random_access_iterator{globalBuff}; } constexpr sentinel end() { return {}; } }; diff --git a/libcxx/test/std/ranges/range.adaptors/range.common.view/borrowing.compile.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.common.view/borrowing.compile.pass.cpp --- a/libcxx/test/std/ranges/range.adaptors/range.common.view/borrowing.compile.pass.cpp +++ b/libcxx/test/std/ranges/range.adaptors/range.common.view/borrowing.compile.pass.cpp @@ -19,19 +19,14 @@ #include "test_iterators.h" struct View : std::ranges::view_base { - friend int* begin(View&); - friend int* begin(View const&); - friend sentinel_wrapper end(View&); - friend sentinel_wrapper end(View const&); + int *begin() const; + sentinel_wrapper end() const; }; struct BorrowableView : std::ranges::view_base { - friend int* begin(BorrowableView&); - friend int* begin(BorrowableView const&); - friend sentinel_wrapper end(BorrowableView&); - friend sentinel_wrapper end(BorrowableView const&); + int *begin() const; + sentinel_wrapper end() const; }; - template<> inline constexpr bool std::ranges::enable_borrowed_range = true; diff --git a/libcxx/test/std/ranges/range.adaptors/range.common.view/ctad.compile.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.common.view/ctad.compile.pass.cpp --- a/libcxx/test/std/ranges/range.adaptors/range.common.view/ctad.compile.pass.cpp +++ b/libcxx/test/std/ranges/range.adaptors/range.common.view/ctad.compile.pass.cpp @@ -19,26 +19,19 @@ #include "test_iterators.h" struct View : std::ranges::view_base { - friend int* begin(View&); - friend int* begin(View const&); - friend sentinel_wrapper end(View&); - friend sentinel_wrapper end(View const&); + int *begin() const; + sentinel_wrapper end() const; }; struct Range { - friend int* begin(Range&); - friend int* begin(Range const&); - friend sentinel_wrapper end(Range&); - friend sentinel_wrapper end(Range const&); + int *begin() const; + sentinel_wrapper end() const; }; struct BorrowedRange { - friend int* begin(BorrowedRange&); - friend int* begin(BorrowedRange const&); - friend sentinel_wrapper end(BorrowedRange&); - friend sentinel_wrapper end(BorrowedRange const&); + int *begin() const; + sentinel_wrapper end() const; }; - template<> inline constexpr bool std::ranges::enable_borrowed_range = true; diff --git a/libcxx/test/std/ranges/range.adaptors/range.common.view/types.h b/libcxx/test/std/ranges/range.adaptors/range.common.view/types.h --- a/libcxx/test/std/ranges/range.adaptors/range.common.view/types.h +++ b/libcxx/test/std/ranges/range.adaptors/range.common.view/types.h @@ -16,64 +16,43 @@ struct DefaultConstructibleView : std::ranges::view_base { int* begin_ = nullptr; int* end_ = nullptr; - - DefaultConstructibleView() = default; - friend constexpr int* begin(DefaultConstructibleView& view) { return view.begin_; } - friend constexpr int* begin(DefaultConstructibleView const& view) { return view.begin_; } - friend constexpr sentinel_wrapper end(DefaultConstructibleView& view) { - return sentinel_wrapper(view.end_); - } - friend constexpr sentinel_wrapper end(DefaultConstructibleView const& view) { - return sentinel_wrapper(view.end_); - } + explicit DefaultConstructibleView() = default; + constexpr int *begin() const { return begin_; } + constexpr auto end() const { return sentinel_wrapper(end_); } }; +static_assert(std::ranges::view); +static_assert(std::default_initializable); struct ContiguousView : std::ranges::view_base { int* begin_; int* end_; - - constexpr ContiguousView(int* b, int* e) : begin_(b), end_(e) { } + constexpr explicit ContiguousView(int* b, int* e) : begin_(b), end_(e) { } constexpr ContiguousView(ContiguousView&&) = default; constexpr ContiguousView& operator=(ContiguousView&&) = default; - friend constexpr int* begin(ContiguousView& view) { return view.begin_; } - friend constexpr int* begin(ContiguousView const& view) { return view.begin_; } - friend constexpr sentinel_wrapper end(ContiguousView& view) { - return sentinel_wrapper{view.end_}; - } - friend constexpr sentinel_wrapper end(ContiguousView const& view) { - return sentinel_wrapper{view.end_}; - } + constexpr int *begin() const { return begin_; } + constexpr auto end() const { return sentinel_wrapper(end_); } }; +static_assert( std::ranges::view); +static_assert( std::ranges::contiguous_range); +static_assert(!std::copyable); struct CopyableView : std::ranges::view_base { int* begin_; int* end_; - - constexpr CopyableView(int* b, int* e) : begin_(b), end_(e) { } - friend constexpr int* begin(CopyableView& view) { return view.begin_; } - friend constexpr int* begin(CopyableView const& view) { return view.begin_; } - friend constexpr sentinel_wrapper end(CopyableView& view) { - return sentinel_wrapper{view.end_}; - } - friend constexpr sentinel_wrapper end(CopyableView const& view) { - return sentinel_wrapper{view.end_}; - } + constexpr explicit CopyableView(int* b, int* e) : begin_(b), end_(e) { } + constexpr int *begin() const { return begin_; } + constexpr auto end() const { return sentinel_wrapper(end_); } }; +static_assert(std::ranges::view); +static_assert(std::copyable); using ForwardIter = forward_iterator; struct SizedForwardView : std::ranges::view_base { int* begin_; int* end_; - - constexpr SizedForwardView(int* b, int* e) : begin_(b), end_(e) { } - friend constexpr ForwardIter begin(SizedForwardView& view) { return ForwardIter(view.begin_); } - friend constexpr ForwardIter begin(SizedForwardView const& view) { return ForwardIter(view.begin_); } - friend constexpr sentinel_wrapper end(SizedForwardView& view) { - return sentinel_wrapper{ForwardIter(view.end_)}; - } - friend constexpr sentinel_wrapper end(SizedForwardView const& view) { - return sentinel_wrapper{ForwardIter(view.end_)}; - } + constexpr explicit SizedForwardView(int* b, int* e) : begin_(b), end_(e) { } + constexpr auto begin() const { return forward_iterator(begin_); } + constexpr auto end() const { return sentinel_wrapper>(forward_iterator(end_)); } }; // Required to make SizedForwardView a sized view. constexpr auto operator-(sentinel_wrapper sent, ForwardIter iter) { @@ -82,21 +61,17 @@ constexpr auto operator-(ForwardIter iter, sentinel_wrapper sent) { return iter.base() - sent.base().base(); } +static_assert(std::ranges::view); +static_assert(std::ranges::forward_range); +static_assert(std::ranges::sized_range); using RandomAccessIter = random_access_iterator; struct SizedRandomAccessView : std::ranges::view_base { int* begin_; int* end_; - - constexpr SizedRandomAccessView(int* b, int* e) : begin_(b), end_(e) { } - friend constexpr RandomAccessIter begin(SizedRandomAccessView& view) { return RandomAccessIter(view.begin_); } - friend constexpr RandomAccessIter begin(SizedRandomAccessView const& view) { return RandomAccessIter(view.begin_); } - friend constexpr sentinel_wrapper end(SizedRandomAccessView& view) { - return sentinel_wrapper{RandomAccessIter(view.end_)}; - } - friend constexpr sentinel_wrapper end(SizedRandomAccessView const& view) { - return sentinel_wrapper{RandomAccessIter(view.end_)}; - } + constexpr explicit SizedRandomAccessView(int* b, int* e) : begin_(b), end_(e) { } + constexpr auto begin() const { return random_access_iterator(begin_); } + constexpr auto end() const { return sentinel_wrapper>(random_access_iterator(end_)); } }; // Required to make SizedRandomAccessView a sized view. constexpr auto operator-(sentinel_wrapper sent, RandomAccessIter iter) { @@ -105,29 +80,28 @@ constexpr auto operator-(RandomAccessIter iter, sentinel_wrapper sent) { return iter.base() - sent.base().base(); } +static_assert(std::ranges::view); +static_assert(std::ranges::random_access_range); +static_assert(std::ranges::sized_range); struct CommonView : std::ranges::view_base { int* begin_; int* end_; constexpr explicit CommonView(int* b, int* e) : begin_(b), end_(e) { } - friend constexpr int* begin(CommonView& view) { return view.begin_; } - friend constexpr int* begin(CommonView const& view) { return view.begin_; } - friend constexpr int* end(CommonView& view) { return view.end_; } - friend constexpr int* end(CommonView const& view) { return view.end_; } + constexpr int *begin() const { return begin_; } + constexpr int *end() const { return end_; } }; -static_assert(std::ranges::range); +static_assert(std::ranges::view); static_assert(std::ranges::common_range); struct NonCommonView : std::ranges::view_base { int* begin_; int* end_; constexpr explicit NonCommonView(int* b, int* e) : begin_(b), end_(e) { } - friend constexpr int* begin(NonCommonView& view) { return view.begin_; } - friend constexpr int* begin(NonCommonView const& view) { return view.begin_; } - friend constexpr sentinel_wrapper end(NonCommonView& view) { return sentinel_wrapper(view.end_); } - friend constexpr sentinel_wrapper end(NonCommonView const& view) { return sentinel_wrapper(view.end_); } + constexpr int *begin() const { return begin_; } + constexpr auto end() const { return sentinel_wrapper(end_); } }; -static_assert( std::ranges::range); +static_assert( std::ranges::view); static_assert(!std::ranges::common_range); #endif // TEST_STD_RANGES_RANGE_ADAPTORS_RANGE_COMMON_VIEW_TYPES_H diff --git a/libcxx/test/std/ranges/range.adaptors/range.drop/types.h b/libcxx/test/std/ranges/range.adaptors/range.drop/types.h --- a/libcxx/test/std/ranges/range.adaptors/range.drop/types.h +++ b/libcxx/test/std/ranges/range.adaptors/range.drop/types.h @@ -16,102 +16,81 @@ struct ContiguousView : std::ranges::view_base { int start_; - constexpr ContiguousView(int start = 0) : start_(start) {} + constexpr explicit ContiguousView(int start = 0) : start_(start) {} constexpr ContiguousView(ContiguousView&&) = default; constexpr ContiguousView& operator=(ContiguousView&&) = default; - friend constexpr int* begin(ContiguousView& view) { return globalBuff + view.start_; } - friend constexpr int* begin(ContiguousView const& view) { return globalBuff + view.start_; } - friend constexpr int* end(ContiguousView&) { return globalBuff + 8; } - friend constexpr int* end(ContiguousView const&) { return globalBuff + 8; } + constexpr int *begin() const { return globalBuff + start_; } + constexpr int *end() const { return globalBuff + 8; } }; +static_assert( std::ranges::view); +static_assert( std::ranges::contiguous_range); +static_assert(!std::copyable); struct CopyableView : std::ranges::view_base { int start_; - constexpr CopyableView(int start = 0) : start_(start) {} + constexpr explicit CopyableView(int start = 0) : start_(start) {} constexpr CopyableView(CopyableView const&) = default; constexpr CopyableView& operator=(CopyableView const&) = default; - friend constexpr int* begin(CopyableView& view) { return globalBuff + view.start_; } - friend constexpr int* begin(CopyableView const& view) { return globalBuff + view.start_; } - friend constexpr int* end(CopyableView&) { return globalBuff + 8; } - friend constexpr int* end(CopyableView const&) { return globalBuff + 8; } + constexpr int *begin() const { return globalBuff + start_; } + constexpr int *end() const { return globalBuff + 8; } }; using ForwardIter = forward_iterator; struct ForwardView : std::ranges::view_base { - constexpr ForwardView() = default; + constexpr explicit ForwardView() = default; constexpr ForwardView(ForwardView&&) = default; constexpr ForwardView& operator=(ForwardView&&) = default; - friend constexpr ForwardIter begin(ForwardView&) { return ForwardIter(globalBuff); } - friend constexpr ForwardIter begin(ForwardView const&) { return ForwardIter(globalBuff); } - friend constexpr ForwardIter end(ForwardView&) { return ForwardIter(globalBuff + 8); } - friend constexpr ForwardIter end(ForwardView const&) { return ForwardIter(globalBuff + 8); } + constexpr forward_iterator begin() const { return forward_iterator(globalBuff); } + constexpr forward_iterator end() const { return forward_iterator(globalBuff + 8); } }; struct ForwardRange { ForwardIter begin() const; ForwardIter end() const; - ForwardIter begin(); - ForwardIter end(); }; struct ThrowingDefaultCtorForwardView : std::ranges::view_base { ThrowingDefaultCtorForwardView() noexcept(false); ForwardIter begin() const; ForwardIter end() const; - ForwardIter begin(); - ForwardIter end(); }; struct NoDefaultCtorForwardView : std::ranges::view_base { NoDefaultCtorForwardView() = delete; ForwardIter begin() const; ForwardIter end() const; - ForwardIter begin(); - ForwardIter end(); }; struct BorrowableRange { - friend int* begin(BorrowableRange const& range); - friend int* end(BorrowableRange const&); - friend int* begin(BorrowableRange& range); - friend int* end(BorrowableRange&); + int *begin() const; + int *end() const; }; - template<> inline constexpr bool std::ranges::enable_borrowed_range = true; struct BorrowableView : std::ranges::view_base { - friend int* begin(BorrowableView const& range); - friend int* end(BorrowableView const&); - friend int* begin(BorrowableView& range); - friend int* end(BorrowableView&); + int *begin() const; + int *end() const; }; - template<> inline constexpr bool std::ranges::enable_borrowed_range = true; struct InputView : std::ranges::view_base { constexpr cpp20_input_iterator begin() const { return cpp20_input_iterator(globalBuff); } constexpr int* end() const { return globalBuff + 8; } - constexpr cpp20_input_iterator begin() { return cpp20_input_iterator(globalBuff); } - constexpr int* end() { return globalBuff + 8; } }; - +// TODO: remove these bogus operators constexpr bool operator==(const cpp20_input_iterator &lhs, int* rhs) { return lhs.base() == rhs; } constexpr bool operator==(int* lhs, const cpp20_input_iterator &rhs) { return rhs.base() == lhs; } struct Range { - friend int* begin(Range const&); - friend int* end(Range const&); - friend int* begin(Range&); - friend int* end(Range&); + int *begin() const; + int *end() const; }; using CountedIter = stride_counting_iterator>; struct CountedView : std::ranges::view_base { - constexpr CountedIter begin() { return CountedIter(ForwardIter(globalBuff)); } constexpr CountedIter begin() const { return CountedIter(ForwardIter(globalBuff)); } - constexpr CountedIter end() { return CountedIter(ForwardIter(globalBuff + 8)); } constexpr CountedIter end() const { return CountedIter(ForwardIter(globalBuff + 8)); } }; diff --git a/libcxx/test/std/ranges/range.adaptors/range.join.view/types.h b/libcxx/test/std/ranges/range.adaptors/range.join.view/types.h --- a/libcxx/test/std/ranges/range.adaptors/range.join.view/types.h +++ b/libcxx/test/std/ranges/range.adaptors/range.join.view/types.h @@ -56,7 +56,7 @@ constexpr T *end() { return ptr_ + size_; } constexpr const T *end() const { return ptr_ + size_; } }; - +// TODO: remove these bogus operators template constexpr bool operator==(const cpp20_input_iterator &lhs, T *rhs) { return lhs.base() == rhs; } template @@ -73,7 +73,7 @@ constexpr int *end() { return ptr_ + size_; } constexpr const int *end() const { return ptr_ + size_; } }; - +// TODO: remove these bogus operators constexpr bool operator==(const cpp17_input_iterator &lhs, const int* rhs) { return lhs.base() == rhs; } constexpr bool operator==(const int* lhs, const cpp17_input_iterator &rhs) { return rhs.base() == lhs; } @@ -86,7 +86,7 @@ constexpr CopyableChild *end() { return ptr_ + 4; } constexpr const CopyableChild *end() const { return ptr_ + 4; } }; - +// TODO: remove these bogus operators constexpr bool operator==(const cpp17_input_iterator &lhs, const CopyableChild *rhs) { return lhs.base() == rhs; } constexpr bool operator==(const CopyableChild *lhs, const cpp17_input_iterator &rhs) { return rhs.base() == lhs; } @@ -133,7 +133,7 @@ ValueView& operator=(const ValueView&) = delete; constexpr InputValueIter begin() { return ptr_; } - constexpr const InputValueIter begin() const { return ptr_; } + constexpr InputValueIter begin() const { return ptr_; } constexpr T *end() { return ptr_.ptr_ + 4; } constexpr const T *end() const { return ptr_.ptr_ + 4; } }; diff --git a/libcxx/test/std/ranges/range.adaptors/range.reverse/types.h b/libcxx/test/std/ranges/range.adaptors/range.reverse/types.h --- a/libcxx/test/std/ranges/range.adaptors/range.reverse/types.h +++ b/libcxx/test/std/ranges/range.adaptors/range.reverse/types.h @@ -23,6 +23,10 @@ constexpr bidirectional_iterator end() { return bidirectional_iterator{end_}; } constexpr bidirectional_iterator end() const { return bidirectional_iterator{end_}; } }; +static_assert( std::ranges::bidirectional_range); +static_assert( std::ranges::common_range); +static_assert( std::ranges::view); +static_assert( std::copyable); enum CopyCategory { MoveOnly, Copyable }; template @@ -44,5 +48,13 @@ constexpr sent_t end() { return sent_t{bidirectional_iterator{end_}}; } constexpr sent_const_t end() const { return sent_const_t{bidirectional_iterator{end_}}; } }; +static_assert( std::ranges::bidirectional_range>); +static_assert(!std::ranges::common_range>); +static_assert( std::ranges::view>); +static_assert(!std::copyable>); +static_assert( std::ranges::bidirectional_range>); +static_assert(!std::ranges::common_range>); +static_assert( std::ranges::view>); +static_assert( std::copyable>); #endif // TEST_STD_RANGES_RANGE_ADAPTORS_RANGE_REVERSE_TYPES_H diff --git a/libcxx/test/std/ranges/range.adaptors/range.take/begin.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.take/begin.pass.cpp --- a/libcxx/test/std/ranges/range.adaptors/range.take/begin.pass.cpp +++ b/libcxx/test/std/ranges/range.adaptors/range.take/begin.pass.cpp @@ -26,14 +26,14 @@ // sized_range && random_access_iterator { - std::ranges::take_view tv(SizedRandomAccessView{buffer}, 4); - assert(tv.begin() == begin(SizedRandomAccessView(buffer))); + std::ranges::take_view tv(SizedRandomAccessView(buffer), 4); + assert(tv.begin() == SizedRandomAccessView(buffer).begin()); ASSERT_SAME_TYPE(decltype(tv.begin()), RandomAccessIter); } { - const std::ranges::take_view tv(SizedRandomAccessView{buffer}, 4); - assert(tv.begin() == begin(SizedRandomAccessView(buffer))); + const std::ranges::take_view tv(SizedRandomAccessView(buffer), 4); + assert(tv.begin() == SizedRandomAccessView(buffer).begin()); ASSERT_SAME_TYPE(decltype(tv.begin()), RandomAccessIter); } diff --git a/libcxx/test/std/ranges/range.adaptors/range.take/types.h b/libcxx/test/std/ranges/range.adaptors/range.take/types.h --- a/libcxx/test/std/ranges/range.adaptors/range.take/types.h +++ b/libcxx/test/std/ranges/range.adaptors/range.take/types.h @@ -10,38 +10,34 @@ struct ContiguousView : std::ranges::view_base { int *ptr_; - constexpr ContiguousView(int* ptr) : ptr_(ptr) {} + constexpr explicit ContiguousView(int* ptr) : ptr_(ptr) {} ContiguousView(ContiguousView&&) = default; ContiguousView& operator=(ContiguousView&&) = default; - constexpr int* begin() {return ptr_;} constexpr int* begin() const {return ptr_;} - constexpr sentinel_wrapper end() {return sentinel_wrapper{ptr_ + 8};} constexpr sentinel_wrapper end() const {return sentinel_wrapper{ptr_ + 8};} }; +static_assert( std::ranges::view); +static_assert( std::ranges::contiguous_range); +static_assert(!std::copyable); struct CopyableView : std::ranges::view_base { int *ptr_; - constexpr CopyableView(int* ptr) : ptr_(ptr) {} + constexpr explicit CopyableView(int* ptr) : ptr_(ptr) {} - constexpr int* begin() {return ptr_;} constexpr int* begin() const {return ptr_;} - constexpr sentinel_wrapper end() {return sentinel_wrapper{ptr_ + 8};} constexpr sentinel_wrapper end() const {return sentinel_wrapper{ptr_ + 8};} }; +static_assert(std::ranges::view); +static_assert(std::ranges::contiguous_range); +static_assert(std::copyable); using ForwardIter = forward_iterator; struct SizedForwardView : std::ranges::view_base { int *ptr_; - constexpr SizedForwardView(int* ptr) : ptr_(ptr) {} - friend constexpr ForwardIter begin(SizedForwardView& view) { return ForwardIter(view.ptr_); } - friend constexpr ForwardIter begin(SizedForwardView const& view) { return ForwardIter(view.ptr_); } - friend constexpr sentinel_wrapper end(SizedForwardView& view) { - return sentinel_wrapper{ForwardIter(view.ptr_ + 8)}; - } - friend constexpr sentinel_wrapper end(SizedForwardView const& view) { - return sentinel_wrapper{ForwardIter(view.ptr_ + 8)}; - } + constexpr explicit SizedForwardView(int* ptr) : ptr_(ptr) {} + constexpr auto begin() const { return ForwardIter(ptr_); } + constexpr auto end() const { return sentinel_wrapper(ForwardIter(ptr_ + 8)); } }; // Required to make SizedForwardView a sized view. constexpr auto operator-(sentinel_wrapper sent, ForwardIter iter) { @@ -50,19 +46,16 @@ constexpr auto operator-(ForwardIter iter, sentinel_wrapper sent) { return iter.base() - sent.base().base(); } +static_assert(std::ranges::view); +static_assert(std::ranges::forward_range); +static_assert(std::ranges::sized_range); using RandomAccessIter = random_access_iterator; struct SizedRandomAccessView : std::ranges::view_base { int *ptr_; - constexpr SizedRandomAccessView(int* ptr) : ptr_(ptr) {} - friend constexpr RandomAccessIter begin(SizedRandomAccessView& view) { return RandomAccessIter(view.ptr_); } - friend constexpr RandomAccessIter begin(SizedRandomAccessView const& view) { return RandomAccessIter(view.ptr_); } - friend constexpr sentinel_wrapper end(SizedRandomAccessView& view) { - return sentinel_wrapper{RandomAccessIter(view.ptr_ + 8)}; - } - friend constexpr sentinel_wrapper end(SizedRandomAccessView const& view) { - return sentinel_wrapper{RandomAccessIter(view.ptr_ + 8)}; - } + constexpr explicit SizedRandomAccessView(int* ptr) : ptr_(ptr) {} + constexpr auto begin() const { return RandomAccessIter(ptr_); } + constexpr auto end() const { return sentinel_wrapper(RandomAccessIter(ptr_ + 8)); } }; // Required to make SizedRandomAccessView a sized view. constexpr auto operator-(sentinel_wrapper sent, RandomAccessIter iter) { @@ -71,5 +64,8 @@ constexpr auto operator-(RandomAccessIter iter, sentinel_wrapper sent) { return iter.base() - sent.base().base(); } +static_assert(std::ranges::view); +static_assert(std::ranges::random_access_range); +static_assert(std::ranges::sized_range); #endif // TEST_STD_RANGES_RANGE_ADAPTORS_RANGE_TAKE_TYPES_H diff --git a/libcxx/test/std/ranges/range.adaptors/range.transform/types.h b/libcxx/test/std/ranges/range.adaptors/range.transform/types.h --- a/libcxx/test/std/ranges/range.adaptors/range.transform/types.h +++ b/libcxx/test/std/ranges/range.adaptors/range.transform/types.h @@ -18,87 +18,87 @@ struct ContiguousView : std::ranges::view_base { int start_; int *ptr_; - constexpr ContiguousView(int* ptr = globalBuff, int start = 0) : start_(start), ptr_(ptr) {} + constexpr explicit ContiguousView(int* ptr = globalBuff, int start = 0) : start_(start), ptr_(ptr) {} constexpr ContiguousView(ContiguousView&&) = default; constexpr ContiguousView& operator=(ContiguousView&&) = default; - friend constexpr int* begin(ContiguousView& view) { return view.ptr_ + view.start_; } - friend constexpr int* begin(ContiguousView const& view) { return view.ptr_ + view.start_; } - friend constexpr int* end(ContiguousView& view) { return view.ptr_ + 8; } - friend constexpr int* end(ContiguousView const& view) { return view.ptr_ + 8; } + constexpr int *begin() const { return ptr_ + start_; } + constexpr int *end() const { return ptr_ + 8; } }; +static_assert( std::ranges::view); +static_assert( std::ranges::contiguous_range); +static_assert(!std::copyable); struct CopyableView : std::ranges::view_base { int start_; - constexpr CopyableView(int start = 0) : start_(start) {} + constexpr explicit CopyableView(int start = 0) : start_(start) {} constexpr CopyableView(CopyableView const&) = default; constexpr CopyableView& operator=(CopyableView const&) = default; - friend constexpr int* begin(CopyableView& view) { return globalBuff + view.start_; } - friend constexpr int* begin(CopyableView const& view) { return globalBuff + view.start_; } - friend constexpr int* end(CopyableView&) { return globalBuff + 8; } - friend constexpr int* end(CopyableView const&) { return globalBuff + 8; } + constexpr int *begin() const { return globalBuff + start_; } + constexpr int *end() const { return globalBuff + 8; } }; +static_assert(std::ranges::view); +static_assert(std::ranges::contiguous_range); +static_assert(std::copyable); using ForwardIter = forward_iterator; struct ForwardView : std::ranges::view_base { int *ptr_; - constexpr ForwardView(int* ptr = globalBuff) : ptr_(ptr) {} + constexpr explicit ForwardView(int* ptr = globalBuff) : ptr_(ptr) {} constexpr ForwardView(ForwardView&&) = default; constexpr ForwardView& operator=(ForwardView&&) = default; - friend constexpr ForwardIter begin(ForwardView& view) { return ForwardIter(view.ptr_); } - friend constexpr ForwardIter begin(ForwardView const& view) { return ForwardIter(view.ptr_); } - friend constexpr ForwardIter end(ForwardView& view) { return ForwardIter(view.ptr_ + 8); } - friend constexpr ForwardIter end(ForwardView const& view) { return ForwardIter(view.ptr_ + 8); } + constexpr auto begin() const { return ForwardIter(ptr_); } + constexpr auto end() const { return ForwardIter(ptr_ + 8); } }; +static_assert(std::ranges::view); +static_assert(std::ranges::forward_range); using ForwardRange = test_common_range; +static_assert(!std::ranges::view); +static_assert( std::ranges::forward_range); using RandomAccessIter = random_access_iterator; struct RandomAccessView : std::ranges::view_base { RandomAccessIter begin() const noexcept; RandomAccessIter end() const noexcept; - RandomAccessIter begin() noexcept; - RandomAccessIter end() noexcept; }; +static_assert( std::ranges::view); +static_assert( std::ranges::random_access_range); using BidirectionalIter = bidirectional_iterator; struct BidirectionalView : std::ranges::view_base { BidirectionalIter begin() const; BidirectionalIter end() const; - BidirectionalIter begin(); - BidirectionalIter end(); }; +static_assert( std::ranges::view); +static_assert( std::ranges::bidirectional_range); struct BorrowableRange { - friend int* begin(BorrowableRange const& range); - friend int* end(BorrowableRange const&); - friend int* begin(BorrowableRange& range); - friend int* end(BorrowableRange&); + int *begin() const; + int *end() const; }; - template<> inline constexpr bool std::ranges::enable_borrowed_range = true; +static_assert(!std::ranges::view); +static_assert( std::ranges::contiguous_range); +static_assert( std::ranges::borrowed_range); struct InputView : std::ranges::view_base { int *ptr_; - constexpr InputView(int* ptr = globalBuff) : ptr_(ptr) {} + constexpr explicit InputView(int* ptr = globalBuff) : ptr_(ptr) {} constexpr cpp20_input_iterator begin() const { return cpp20_input_iterator(ptr_); } - constexpr int* end() const { return ptr_ + 8; } - constexpr cpp20_input_iterator begin() { return cpp20_input_iterator(ptr_); } - constexpr int* end() { return ptr_ + 8; } + constexpr int *end() const { return ptr_ + 8; } }; - +// TODO: remove these bogus operators constexpr bool operator==(const cpp20_input_iterator &lhs, int* rhs) { return lhs.base() == rhs; } constexpr bool operator==(int* lhs, const cpp20_input_iterator &rhs) { return rhs.base() == lhs; } struct SizedSentinelView : std::ranges::view_base { int count_; - constexpr SizedSentinelView(int count = 8) : count_(count) {} - constexpr RandomAccessIter begin() const { return RandomAccessIter(globalBuff); } - constexpr int* end() const { return globalBuff + count_; } - constexpr RandomAccessIter begin() { return RandomAccessIter(globalBuff); } - constexpr int* end() { return globalBuff + count_; } + constexpr explicit SizedSentinelView(int count = 8) : count_(count) {} + constexpr auto begin() const { return RandomAccessIter(globalBuff); } + constexpr int *end() const { return globalBuff + count_; } }; - +// TODO: remove these bogus operators constexpr auto operator- (const RandomAccessIter &lhs, int* rhs) { return lhs.base() - rhs; } constexpr auto operator- (int* lhs, const RandomAccessIter &rhs) { return lhs - rhs.base(); } constexpr bool operator==(const RandomAccessIter &lhs, int* rhs) { return lhs.base() == rhs; } @@ -107,25 +107,20 @@ struct SizedSentinelNotConstView : std::ranges::view_base { ForwardIter begin() const; int *end() const; - ForwardIter begin(); - int *end(); size_t size(); }; +// TODO: remove these bogus operators bool operator==(const ForwardIter &lhs, int* rhs); bool operator==(int* lhs, const ForwardIter &rhs); struct Range { - friend int* begin(Range const&); - friend int* end(Range const&); - friend int* begin(Range&); - friend int* end(Range&); + int *begin() const; + int *end() const; }; using CountedIter = stride_counting_iterator>; struct CountedView : std::ranges::view_base { - constexpr CountedIter begin() { return CountedIter(ForwardIter(globalBuff)); } constexpr CountedIter begin() const { return CountedIter(ForwardIter(globalBuff)); } - constexpr CountedIter end() { return CountedIter(ForwardIter(globalBuff + 8)); } constexpr CountedIter end() const { return CountedIter(ForwardIter(globalBuff + 8)); } };