[libcxx-commits] [libcxx] 3666dd7 - [libc++] [test] Change a lot of free begin/end pairs to members. NFCI.
Arthur O'Dwyer via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Oct 6 13:43:52 PDT 2021
Author: Arthur O'Dwyer
Date: 2021-10-06T16:43:03-04:00
New Revision: 3666dd795d9e2114e49bd58ace042b663d6f8a3a
URL: https://github.com/llvm/llvm-project/commit/3666dd795d9e2114e49bd58ace042b663d6f8a3a
DIFF: https://github.com/llvm/llvm-project/commit/3666dd795d9e2114e49bd58ace042b663d6f8a3a.diff
LOG: [libc++] [test] Change a lot of free begin/end pairs to members. NFCI.
If you have a `begin() const` member, you don't need a `begin()` member
unless you want it to do something different (e.g. have a different return
type). So in general, //view// types don't need `begin()` non-const members.
Also, static_assert some things about the types in "types.h", so that we
don't accidentally break those properties under refactoring.
Differential Revision: https://reviews.llvm.org/D111231
Added:
Modified:
libcxx/test/libcxx/ranges/range.utility.helpers/simple_view.compile.pass.cpp
libcxx/test/std/ranges/range.access/range.prim/data.pass.cpp
libcxx/test/std/ranges/range.adaptors/range.all/all.pass.cpp
libcxx/test/std/ranges/range.adaptors/range.common.view/borrowing.compile.pass.cpp
libcxx/test/std/ranges/range.adaptors/range.common.view/ctad.compile.pass.cpp
libcxx/test/std/ranges/range.adaptors/range.common.view/types.h
libcxx/test/std/ranges/range.adaptors/range.drop/types.h
libcxx/test/std/ranges/range.adaptors/range.join.view/types.h
libcxx/test/std/ranges/range.adaptors/range.reverse/types.h
libcxx/test/std/ranges/range.adaptors/range.take/begin.pass.cpp
libcxx/test/std/ranges/range.adaptors/range.take/types.h
libcxx/test/std/ranges/range.adaptors/range.transform/types.h
Removed:
################################################################################
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
index d4e89604f31a..7aef1bab92a5 100644
--- 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<int*> end(DifferentSentinel&);
- friend sentinel_wrapper<int*> end(DifferentSentinel const&);
+ int *begin() const;
+ sentinel_wrapper<int*> end() const;
};
static_assert( std::ranges::__simple_view<SimpleView>);
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
index fad6d301d5ff..b02c82306bcb 100644
--- 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 @@ struct BeginMemberContiguousIterator {
constexpr ContiguousIter begin() const { return ContiguousIter(buff); }
};
-
static_assert( std::is_invocable_v<RangeDataT, BeginMemberContiguousIterator &>);
static_assert(!std::is_invocable_v<RangeDataT, BeginMemberContiguousIterator &&>);
+static_assert( std::is_invocable_v<RangeDataT, BeginMemberContiguousIterator const&>);
+static_assert(!std::is_invocable_v<RangeDataT, BeginMemberContiguousIterator const&&>);
struct BeginMemberRandomAccess {
int buff[8];
random_access_iterator<const int*> begin() const;
};
-
static_assert(!std::is_invocable_v<RangeDataT, BeginMemberRandomAccess>);
static_assert(!std::is_invocable_v<RangeDataT, BeginMemberRandomAccess const>);
static_assert(!std::is_invocable_v<RangeDataT, BeginMemberRandomAccess const&>);
@@ -127,11 +127,14 @@ struct BeginFriendContiguousIterator {
return ContiguousIter(iter.buff);
}
};
+static_assert( std::is_invocable_v<RangeDataT, BeginMemberContiguousIterator &>);
+static_assert(!std::is_invocable_v<RangeDataT, BeginMemberContiguousIterator &&>);
+static_assert( std::is_invocable_v<RangeDataT, BeginMemberContiguousIterator const&>);
+static_assert(!std::is_invocable_v<RangeDataT, BeginMemberContiguousIterator const&&>);
struct BeginFriendRandomAccess {
friend random_access_iterator<const int*> begin(const BeginFriendRandomAccess iter);
};
-
static_assert(!std::is_invocable_v<RangeDataT, BeginFriendRandomAccess>);
static_assert(!std::is_invocable_v<RangeDataT, BeginFriendRandomAccess const>);
static_assert(!std::is_invocable_v<RangeDataT, BeginFriendRandomAccess const&>);
@@ -141,16 +144,18 @@ struct BeginMemberRvalue {
ContiguousIter begin() &&;
};
-
static_assert(!std::is_invocable_v<RangeDataT, BeginMemberRvalue&&>);
static_assert(!std::is_invocable_v<RangeDataT, BeginMemberRvalue const&>);
struct BeginMemberBorrowingEnabled {
constexpr contiguous_iterator<int*> begin() { return contiguous_iterator<int*>{&globalBuff[1]}; }
};
-
template<>
inline constexpr bool std::ranges::enable_borrowed_range<BeginMemberBorrowingEnabled> = true;
+static_assert( std::is_invocable_v<RangeDataT, BeginMemberBorrowingEnabled &>);
+static_assert( std::is_invocable_v<RangeDataT, BeginMemberBorrowingEnabled &&>);
+static_assert(!std::is_invocable_v<RangeDataT, BeginMemberBorrowingEnabled const&>);
+static_assert(!std::is_invocable_v<RangeDataT, BeginMemberBorrowingEnabled const&&>);
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
index 508326dbc225..c24435af90d7 100644
--- 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 @@ struct View : std::ranges::view_base {
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<View<true>>);
static_assert(std::ranges::view<View<false>>);
@@ -46,10 +44,8 @@ struct CopyableView : std::ranges::view_base {
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<CopyableView<true>>);
static_assert(std::ranges::view<CopyableView<false>>);
@@ -57,19 +53,15 @@ static_assert(std::ranges::view<CopyableView<false>>);
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<BorrowableRange> = true;
@@ -80,7 +72,6 @@ struct RandomAccessRange {
friend constexpr std::ptr
diff _t operator-(sentinel, random_access_iterator<int*>) { return -8; }
friend constexpr std::ptr
diff _t operator-(random_access_iterator<int*>, sentinel) { return 8; }
};
-
constexpr random_access_iterator<int*> begin() { return random_access_iterator<int*>{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
index 84d45f0f9ec1..83283789e8bf 100644
--- 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<int*> end(View&);
- friend sentinel_wrapper<int*> end(View const&);
+ int *begin() const;
+ sentinel_wrapper<int*> end() const;
};
struct BorrowableView : std::ranges::view_base {
- friend int* begin(BorrowableView&);
- friend int* begin(BorrowableView const&);
- friend sentinel_wrapper<int*> end(BorrowableView&);
- friend sentinel_wrapper<int*> end(BorrowableView const&);
+ int *begin() const;
+ sentinel_wrapper<int*> end() const;
};
-
template<>
inline constexpr bool std::ranges::enable_borrowed_range<BorrowableView> = 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
index 8c1e6d7b1de1..5f7fd83f1611 100644
--- 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<int*> end(View&);
- friend sentinel_wrapper<int*> end(View const&);
+ int *begin() const;
+ sentinel_wrapper<int*> end() const;
};
struct Range {
- friend int* begin(Range&);
- friend int* begin(Range const&);
- friend sentinel_wrapper<int*> end(Range&);
- friend sentinel_wrapper<int*> end(Range const&);
+ int *begin() const;
+ sentinel_wrapper<int*> end() const;
};
struct BorrowedRange {
- friend int* begin(BorrowedRange&);
- friend int* begin(BorrowedRange const&);
- friend sentinel_wrapper<int*> end(BorrowedRange&);
- friend sentinel_wrapper<int*> end(BorrowedRange const&);
+ int *begin() const;
+ sentinel_wrapper<int*> end() const;
};
-
template<>
inline constexpr bool std::ranges::enable_borrowed_range<BorrowedRange> = 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
index cbefa07ebadb..98f62c01123f 100644
--- 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<int*> end(DefaultConstructibleView& view) {
- return sentinel_wrapper<int*>(view.end_);
- }
- friend constexpr sentinel_wrapper<int*> end(DefaultConstructibleView const& view) {
- return sentinel_wrapper<int*>(view.end_);
- }
+ explicit DefaultConstructibleView() = default;
+ constexpr int *begin() const { return begin_; }
+ constexpr auto end() const { return sentinel_wrapper<int*>(end_); }
};
+static_assert(std::ranges::view<DefaultConstructibleView>);
+static_assert(std::default_initializable<DefaultConstructibleView>);
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<int*> end(ContiguousView& view) {
- return sentinel_wrapper<int*>{view.end_};
- }
- friend constexpr sentinel_wrapper<int*> end(ContiguousView const& view) {
- return sentinel_wrapper<int*>{view.end_};
- }
+ constexpr int *begin() const { return begin_; }
+ constexpr auto end() const { return sentinel_wrapper<int*>(end_); }
};
+static_assert( std::ranges::view<ContiguousView>);
+static_assert( std::ranges::contiguous_range<ContiguousView>);
+static_assert(!std::copyable<ContiguousView>);
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<int*> end(CopyableView& view) {
- return sentinel_wrapper<int*>{view.end_};
- }
- friend constexpr sentinel_wrapper<int*> end(CopyableView const& view) {
- return sentinel_wrapper<int*>{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<int*>(end_); }
};
+static_assert(std::ranges::view<CopyableView>);
+static_assert(std::copyable<CopyableView>);
using ForwardIter = forward_iterator<int*>;
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<ForwardIter> end(SizedForwardView& view) {
- return sentinel_wrapper<ForwardIter>{ForwardIter(view.end_)};
- }
- friend constexpr sentinel_wrapper<ForwardIter> end(SizedForwardView const& view) {
- return sentinel_wrapper<ForwardIter>{ForwardIter(view.end_)};
- }
+ constexpr explicit SizedForwardView(int* b, int* e) : begin_(b), end_(e) { }
+ constexpr auto begin() const { return forward_iterator<int*>(begin_); }
+ constexpr auto end() const { return sentinel_wrapper<forward_iterator<int*>>(forward_iterator<int*>(end_)); }
};
// Required to make SizedForwardView a sized view.
constexpr auto operator-(sentinel_wrapper<ForwardIter> sent, ForwardIter iter) {
@@ -82,21 +61,17 @@ constexpr auto operator-(sentinel_wrapper<ForwardIter> sent, ForwardIter iter) {
constexpr auto operator-(ForwardIter iter, sentinel_wrapper<ForwardIter> sent) {
return iter.base() - sent.base().base();
}
+static_assert(std::ranges::view<SizedForwardView>);
+static_assert(std::ranges::forward_range<SizedForwardView>);
+static_assert(std::ranges::sized_range<SizedForwardView>);
using RandomAccessIter = random_access_iterator<int*>;
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<RandomAccessIter> end(SizedRandomAccessView& view) {
- return sentinel_wrapper<RandomAccessIter>{RandomAccessIter(view.end_)};
- }
- friend constexpr sentinel_wrapper<RandomAccessIter> end(SizedRandomAccessView const& view) {
- return sentinel_wrapper<RandomAccessIter>{RandomAccessIter(view.end_)};
- }
+ constexpr explicit SizedRandomAccessView(int* b, int* e) : begin_(b), end_(e) { }
+ constexpr auto begin() const { return random_access_iterator<int*>(begin_); }
+ constexpr auto end() const { return sentinel_wrapper<random_access_iterator<int*>>(random_access_iterator<int*>(end_)); }
};
// Required to make SizedRandomAccessView a sized view.
constexpr auto operator-(sentinel_wrapper<RandomAccessIter> sent, RandomAccessIter iter) {
@@ -105,29 +80,28 @@ constexpr auto operator-(sentinel_wrapper<RandomAccessIter> sent, RandomAccessIt
constexpr auto operator-(RandomAccessIter iter, sentinel_wrapper<RandomAccessIter> sent) {
return iter.base() - sent.base().base();
}
+static_assert(std::ranges::view<SizedRandomAccessView>);
+static_assert(std::ranges::random_access_range<SizedRandomAccessView>);
+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) { }
- 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<CommonView>);
+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) { }
- friend constexpr int* begin(NonCommonView& view) { return view.begin_; }
- friend constexpr int* begin(NonCommonView const& view) { return view.begin_; }
- friend constexpr sentinel_wrapper<int*> end(NonCommonView& view) { return sentinel_wrapper<int*>(view.end_); }
- friend constexpr sentinel_wrapper<int*> end(NonCommonView const& view) { return sentinel_wrapper<int*>(view.end_); }
+ constexpr int *begin() const { return begin_; }
+ constexpr auto end() const { return sentinel_wrapper<int*>(end_); }
};
-static_assert( std::ranges::range<NonCommonView>);
+static_assert( std::ranges::view<NonCommonView>);
static_assert(!std::ranges::common_range<NonCommonView>);
#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
index e861f6f029da..19c2a738c968 100644
--- 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 @@ int globalBuff[8];
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<ContiguousView>);
+static_assert( std::ranges::contiguous_range<ContiguousView>);
+static_assert(!std::copyable<ContiguousView>);
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<int*>;
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<int*> begin() const { return forward_iterator<int*>(globalBuff); }
+ constexpr forward_iterator<int*> end() const { return forward_iterator<int*>(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<BorrowableRange> = 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<BorrowableView> = true;
struct InputView : std::ranges::view_base {
constexpr cpp20_input_iterator<int*> begin() const { return cpp20_input_iterator<int*>(globalBuff); }
constexpr int* end() const { return globalBuff + 8; }
- constexpr cpp20_input_iterator<int*> begin() { return cpp20_input_iterator<int*>(globalBuff); }
- constexpr int* end() { return globalBuff + 8; }
};
-
+// TODO: remove these bogus operators
constexpr bool operator==(const cpp20_input_iterator<int*> &lhs, int* rhs) { return lhs.base() == rhs; }
constexpr bool operator==(int* lhs, const cpp20_input_iterator<int*> &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<forward_iterator<int*>>;
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
index 57f79a57485b..661beaa3a92f 100644
--- 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 @@ struct ParentView : std::ranges::view_base {
constexpr T *end() { return ptr_ + size_; }
constexpr const T *end() const { return ptr_ + size_; }
};
-
+// TODO: remove these bogus operators
template<class T>
constexpr bool operator==(const cpp20_input_iterator<T*> &lhs, T *rhs) { return lhs.base() == rhs; }
template<class T>
@@ -73,7 +73,7 @@ struct CopyableChild : std::ranges::view_base {
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<const int*> &lhs, const int* rhs) { return lhs.base() == rhs; }
constexpr bool operator==(const int* lhs, const cpp17_input_iterator<const int*> &rhs) { return rhs.base() == lhs; }
@@ -86,7 +86,7 @@ struct CopyableParent : std::ranges::view_base {
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<const CopyableChild*> &lhs, const CopyableChild *rhs) { return lhs.base() == rhs; }
constexpr bool operator==(const CopyableChild *lhs, const cpp17_input_iterator<const CopyableChild*> &rhs) { return rhs.base() == lhs; }
@@ -133,7 +133,7 @@ struct ValueView : std::ranges::view_base {
ValueView& operator=(const ValueView&) = delete;
constexpr InputValueIter<T> begin() { return ptr_; }
- constexpr const InputValueIter<T> begin() const { return ptr_; }
+ constexpr InputValueIter<T> 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
index ffd4f95a008c..c4c674d812c7 100644
--- 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 @@ struct BidirRange : std::ranges::view_base {
constexpr bidirectional_iterator<int*> end() { return bidirectional_iterator<int*>{end_}; }
constexpr bidirectional_iterator<const int*> end() const { return bidirectional_iterator<const int*>{end_}; }
};
+static_assert( std::ranges::bidirectional_range<BidirRange>);
+static_assert( std::ranges::common_range<BidirRange>);
+static_assert( std::ranges::view<BidirRange>);
+static_assert( std::copyable<BidirRange>);
enum CopyCategory { MoveOnly, Copyable };
template<CopyCategory CC>
@@ -44,5 +48,13 @@ struct BidirSentRange : std::ranges::view_base {
constexpr sent_t end() { return sent_t{bidirectional_iterator<int*>{end_}}; }
constexpr sent_const_t end() const { return sent_const_t{bidirectional_iterator<const int*>{end_}}; }
};
+static_assert( std::ranges::bidirectional_range<BidirSentRange<MoveOnly>>);
+static_assert(!std::ranges::common_range<BidirSentRange<MoveOnly>>);
+static_assert( std::ranges::view<BidirSentRange<MoveOnly>>);
+static_assert(!std::copyable<BidirSentRange<MoveOnly>>);
+static_assert( std::ranges::bidirectional_range<BidirSentRange<Copyable>>);
+static_assert(!std::ranges::common_range<BidirSentRange<Copyable>>);
+static_assert( std::ranges::view<BidirSentRange<Copyable>>);
+static_assert( std::copyable<BidirSentRange<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
index db265eeb5041..556542dce049 100644
--- 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 @@ constexpr bool test() {
// sized_range && random_access_iterator
{
- std::ranges::take_view<SizedRandomAccessView> tv(SizedRandomAccessView{buffer}, 4);
- assert(tv.begin() == begin(SizedRandomAccessView(buffer)));
+ std::ranges::take_view<SizedRandomAccessView> tv(SizedRandomAccessView(buffer), 4);
+ assert(tv.begin() == SizedRandomAccessView(buffer).begin());
ASSERT_SAME_TYPE(decltype(tv.begin()), RandomAccessIter);
}
{
- const std::ranges::take_view<SizedRandomAccessView> tv(SizedRandomAccessView{buffer}, 4);
- assert(tv.begin() == begin(SizedRandomAccessView(buffer)));
+ const std::ranges::take_view<SizedRandomAccessView> 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
index 72563eecfc92..81952c52a767 100644
--- 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<int*> end() {return sentinel_wrapper<int*>{ptr_ + 8};}
constexpr sentinel_wrapper<int*> end() const {return sentinel_wrapper<int*>{ptr_ + 8};}
};
+static_assert( std::ranges::view<ContiguousView>);
+static_assert( std::ranges::contiguous_range<ContiguousView>);
+static_assert(!std::copyable<ContiguousView>);
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<int*> end() {return sentinel_wrapper<int*>{ptr_ + 8};}
constexpr sentinel_wrapper<int*> end() const {return sentinel_wrapper<int*>{ptr_ + 8};}
};
+static_assert(std::ranges::view<CopyableView>);
+static_assert(std::ranges::contiguous_range<CopyableView>);
+static_assert(std::copyable<CopyableView>);
using ForwardIter = forward_iterator<int*>;
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<ForwardIter> end(SizedForwardView& view) {
- return sentinel_wrapper<ForwardIter>{ForwardIter(view.ptr_ + 8)};
- }
- friend constexpr sentinel_wrapper<ForwardIter> end(SizedForwardView const& view) {
- return sentinel_wrapper<ForwardIter>{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>(ForwardIter(ptr_ + 8)); }
};
// Required to make SizedForwardView a sized view.
constexpr auto operator-(sentinel_wrapper<ForwardIter> sent, ForwardIter iter) {
@@ -50,19 +46,16 @@ constexpr auto operator-(sentinel_wrapper<ForwardIter> sent, ForwardIter iter) {
constexpr auto operator-(ForwardIter iter, sentinel_wrapper<ForwardIter> sent) {
return iter.base() - sent.base().base();
}
+static_assert(std::ranges::view<SizedForwardView>);
+static_assert(std::ranges::forward_range<SizedForwardView>);
+static_assert(std::ranges::sized_range<SizedForwardView>);
using RandomAccessIter = random_access_iterator<int*>;
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<RandomAccessIter> end(SizedRandomAccessView& view) {
- return sentinel_wrapper<RandomAccessIter>{RandomAccessIter(view.ptr_ + 8)};
- }
- friend constexpr sentinel_wrapper<RandomAccessIter> end(SizedRandomAccessView const& view) {
- return sentinel_wrapper<RandomAccessIter>{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>(RandomAccessIter(ptr_ + 8)); }
};
// Required to make SizedRandomAccessView a sized view.
constexpr auto operator-(sentinel_wrapper<RandomAccessIter> sent, RandomAccessIter iter) {
@@ -71,5 +64,8 @@ constexpr auto operator-(sentinel_wrapper<RandomAccessIter> sent, RandomAccessIt
constexpr auto operator-(RandomAccessIter iter, sentinel_wrapper<RandomAccessIter> sent) {
return iter.base() - sent.base().base();
}
+static_assert(std::ranges::view<SizedRandomAccessView>);
+static_assert(std::ranges::random_access_range<SizedRandomAccessView>);
+static_assert(std::ranges::sized_range<SizedRandomAccessView>);
#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
index fff7b287f322..24563719cf56 100644
--- 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 @@ int globalBuff[8] = {0,1,2,3,4,5,6,7};
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<ContiguousView>);
+static_assert( std::ranges::contiguous_range<ContiguousView>);
+static_assert(!std::copyable<ContiguousView>);
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<CopyableView>);
+static_assert(std::ranges::contiguous_range<CopyableView>);
+static_assert(std::copyable<CopyableView>);
using ForwardIter = forward_iterator<int*>;
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<ForwardView>);
+static_assert(std::ranges::forward_range<ForwardView>);
using ForwardRange = test_common_range<forward_iterator>;
+static_assert(!std::ranges::view<ForwardRange>);
+static_assert( std::ranges::forward_range<ForwardRange>);
using RandomAccessIter = random_access_iterator<int*>;
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<RandomAccessView>);
+static_assert( std::ranges::random_access_range<RandomAccessView>);
using BidirectionalIter = bidirectional_iterator<int*>;
struct BidirectionalView : std::ranges::view_base {
BidirectionalIter begin() const;
BidirectionalIter end() const;
- BidirectionalIter begin();
- BidirectionalIter end();
};
+static_assert( std::ranges::view<BidirectionalView>);
+static_assert( std::ranges::bidirectional_range<BidirectionalView>);
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<BorrowableRange> = true;
+static_assert(!std::ranges::view<BorrowableRange>);
+static_assert( std::ranges::contiguous_range<BorrowableRange>);
+static_assert( std::ranges::borrowed_range<BorrowableRange>);
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<int*> begin() const { return cpp20_input_iterator<int*>(ptr_); }
- constexpr int* end() const { return ptr_ + 8; }
- constexpr cpp20_input_iterator<int*> begin() { return cpp20_input_iterator<int*>(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<int*> &lhs, int* rhs) { return lhs.base() == rhs; }
constexpr bool operator==(int* lhs, const cpp20_input_iterator<int*> &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 @@ constexpr bool operator==(int* lhs, const RandomAccessIter &rhs) { return rhs.ba
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<forward_iterator<int*>>;
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)); }
};
More information about the libcxx-commits
mailing list