1 #ifndef TEST_STD_RANGES_RANGE_ADAPTORS_RANGE_TRANSFORM_TYPES_H 2 #define TEST_STD_RANGES_RANGE_ADAPTORS_RANGE_TRANSFORM_TYPES_H 3 4 #include "test_macros.h" 5 #include "test_iterators.h" 6 #include "test_range.h" 7 8 int globalBuff[8] = {0,1,2,3,4,5,6,7}; 9 10 template<class T, class F> 11 concept ValidDropView = requires { typename std::ranges::transform_view<T, F>; }; 12 13 struct ContiguousView : std::ranges::view_base { 14 int start_; 15 int *ptr_; start_ContiguousView16 constexpr ContiguousView(int* ptr = globalBuff, int start = 0) : start_(start), ptr_(ptr) {} 17 constexpr ContiguousView(ContiguousView&&) = default; 18 constexpr ContiguousView& operator=(ContiguousView&&) = default; beginContiguousView19 friend constexpr int* begin(ContiguousView& view) { return view.ptr_ + view.start_; } beginContiguousView20 friend constexpr int* begin(ContiguousView const& view) { return view.ptr_ + view.start_; } endContiguousView21 friend constexpr int* end(ContiguousView& view) { return view.ptr_ + 8; } endContiguousView22 friend constexpr int* end(ContiguousView const& view) { return view.ptr_ + 8; } 23 }; 24 25 struct CopyableView : std::ranges::view_base { 26 int start_; start_CopyableView27 constexpr CopyableView(int start = 0) : start_(start) {} 28 constexpr CopyableView(CopyableView const&) = default; 29 constexpr CopyableView& operator=(CopyableView const&) = default; beginCopyableView30 friend constexpr int* begin(CopyableView& view) { return globalBuff + view.start_; } beginCopyableView31 friend constexpr int* begin(CopyableView const& view) { return globalBuff + view.start_; } endCopyableView32 friend constexpr int* end(CopyableView&) { return globalBuff + 8; } endCopyableView33 friend constexpr int* end(CopyableView const&) { return globalBuff + 8; } 34 }; 35 36 using ForwardIter = forward_iterator<int*>; 37 struct ForwardView : std::ranges::view_base { 38 int *ptr_; ptr_ForwardView39 constexpr ForwardView(int* ptr = globalBuff) : ptr_(ptr) {} 40 constexpr ForwardView(ForwardView&&) = default; 41 constexpr ForwardView& operator=(ForwardView&&) = default; beginForwardView42 friend constexpr ForwardIter begin(ForwardView& view) { return ForwardIter(view.ptr_); } beginForwardView43 friend constexpr ForwardIter begin(ForwardView const& view) { return ForwardIter(view.ptr_); } endForwardView44 friend constexpr ForwardIter end(ForwardView& view) { return ForwardIter(view.ptr_ + 8); } endForwardView45 friend constexpr ForwardIter end(ForwardView const& view) { return ForwardIter(view.ptr_ + 8); } 46 }; 47 48 using ForwardRange = test_common_range<forward_iterator>; 49 50 using RandomAccessIter = random_access_iterator<int*>; 51 struct RandomAccessView : std::ranges::view_base { 52 RandomAccessIter begin() const noexcept; 53 RandomAccessIter end() const noexcept; 54 RandomAccessIter begin() noexcept; 55 RandomAccessIter end() noexcept; 56 }; 57 58 using BidirectionalIter = bidirectional_iterator<int*>; 59 struct BidirectionalView : std::ranges::view_base { 60 BidirectionalIter begin() const; 61 BidirectionalIter end() const; 62 BidirectionalIter begin(); 63 BidirectionalIter end(); 64 }; 65 66 struct BorrowableRange { 67 friend int* begin(BorrowableRange const& range); 68 friend int* end(BorrowableRange const&); 69 friend int* begin(BorrowableRange& range); 70 friend int* end(BorrowableRange&); 71 }; 72 73 template<> 74 inline constexpr bool std::ranges::enable_borrowed_range<BorrowableRange> = true; 75 76 struct InputView : std::ranges::view_base { 77 int *ptr_; ptr_InputView78 constexpr InputView(int* ptr = globalBuff) : ptr_(ptr) {} beginInputView79 constexpr cpp20_input_iterator<int*> begin() const { return cpp20_input_iterator<int*>(ptr_); } endInputView80 constexpr int* end() const { return ptr_ + 8; } beginInputView81 constexpr cpp20_input_iterator<int*> begin() { return cpp20_input_iterator<int*>(ptr_); } endInputView82 constexpr int* end() { return ptr_ + 8; } 83 }; 84 85 constexpr bool operator==(const cpp20_input_iterator<int*> &lhs, int* rhs) { return lhs.base() == rhs; } 86 constexpr bool operator==(int* lhs, const cpp20_input_iterator<int*> &rhs) { return rhs.base() == lhs; } 87 88 struct SizedSentinelView : std::ranges::view_base { 89 int count_; count_SizedSentinelView90 constexpr SizedSentinelView(int count = 8) : count_(count) {} beginSizedSentinelView91 constexpr RandomAccessIter begin() const { return RandomAccessIter(globalBuff); } endSizedSentinelView92 constexpr int* end() const { return globalBuff + count_; } beginSizedSentinelView93 constexpr RandomAccessIter begin() { return RandomAccessIter(globalBuff); } endSizedSentinelView94 constexpr int* end() { return globalBuff + count_; } 95 }; 96 97 constexpr auto operator- (const RandomAccessIter &lhs, int* rhs) { return lhs.base() - rhs; } 98 constexpr auto operator- (int* lhs, const RandomAccessIter &rhs) { return lhs - rhs.base(); } 99 constexpr bool operator==(const RandomAccessIter &lhs, int* rhs) { return lhs.base() == rhs; } 100 constexpr bool operator==(int* lhs, const RandomAccessIter &rhs) { return rhs.base() == lhs; } 101 102 struct SizedSentinelNotConstView : std::ranges::view_base { 103 ForwardIter begin() const; 104 int *end() const; 105 ForwardIter begin(); 106 int *end(); 107 size_t size(); 108 }; 109 bool operator==(const ForwardIter &lhs, int* rhs); 110 bool operator==(int* lhs, const ForwardIter &rhs); 111 112 struct Range { 113 friend int* begin(Range const&); 114 friend int* end(Range const&); 115 friend int* begin(Range&); 116 friend int* end(Range&); 117 }; 118 119 using CountedIter = stride_counting_iterator<forward_iterator<int*>>; 120 struct CountedView : std::ranges::view_base { beginCountedView121 constexpr CountedIter begin() { return CountedIter(ForwardIter(globalBuff)); } beginCountedView122 constexpr CountedIter begin() const { return CountedIter(ForwardIter(globalBuff)); } endCountedView123 constexpr CountedIter end() { return CountedIter(ForwardIter(globalBuff + 8)); } endCountedView124 constexpr CountedIter end() const { return CountedIter(ForwardIter(globalBuff + 8)); } 125 }; 126 127 using ThreeWayCompIter = three_way_contiguous_iterator<int*>; 128 struct ThreeWayCompView : std::ranges::view_base { beginThreeWayCompView129 constexpr ThreeWayCompIter begin() { return ThreeWayCompIter(globalBuff); } beginThreeWayCompView130 constexpr ThreeWayCompIter begin() const { return ThreeWayCompIter(globalBuff); } endThreeWayCompView131 constexpr ThreeWayCompIter end() { return ThreeWayCompIter(globalBuff + 8); } endThreeWayCompView132 constexpr ThreeWayCompIter end() const { return ThreeWayCompIter(globalBuff + 8); } 133 }; 134 135 struct Increment { operatorIncrement136 constexpr int operator()(int x) { return x + 1; } 137 }; 138 139 struct IncrementConst { operatorIncrementConst140 constexpr int operator()(int x) const { return x + 1; } 141 }; 142 143 struct IncrementRef { operatorIncrementRef144 constexpr int& operator()(int& x) { return ++x; } 145 }; 146 147 struct IncrementRvalueRef { operatorIncrementRvalueRef148 constexpr int&& operator()(int& x) { return std::move(++x); } 149 }; 150 151 struct IncrementNoexcept { operatorIncrementNoexcept152 constexpr int operator()(int x) noexcept { return x + 1; } 153 }; 154 155 #endif // TEST_STD_RANGES_RANGE_ADAPTORS_RANGE_TRANSFORM_TYPES_H 156