File tree Expand file tree Collapse file tree 5 files changed +32
-9
lines changed
libcxx/iterators/bounded_iter
containers/views/views.span/span.iterators
strings/string.view/string.view.iterators Expand file tree Collapse file tree 5 files changed +32
-9
lines changed Original file line number Diff line number Diff line change @@ -202,7 +202,7 @@ struct __bounded_iter {
202202 operator ==(__bounded_iter const & __x, __bounded_iter const & __y) _NOEXCEPT {
203203 return __x.__current_ == __y.__current_ ;
204204 }
205- # if _LIBCPP_STD_VER <= 17
205+
206206 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR friend bool
207207 operator !=(__bounded_iter const & __x, __bounded_iter const & __y) _NOEXCEPT {
208208 return __x.__current_ != __y.__current_ ;
@@ -224,14 +224,19 @@ struct __bounded_iter {
224224 return __x.__current_ >= __y.__current_ ;
225225 }
226226
227- #else // _LIBCPP_STD_VER <= 17
228-
227+ #if _LIBCPP_STD_VER >= 20
228+ // It is not required that the underlying iterator supports operator<=>.
229+ // Therefore this operator is only conditionally provided, which requires a
230+ // templated function.
231+ template <class _Tp = void >
232+ requires requires (_Iterator const & __i) {
233+ { __i <=> __i } -> same_as<strong_ordering>;
234+ }
229235 _LIBCPP_HIDE_FROM_ABI constexpr friend strong_ordering
230236 operator <=>(__bounded_iter const & __x, __bounded_iter const & __y) noexcept {
231237 return __x.__current_ <=> __y.__current_ ;
232238 }
233-
234- #endif // _LIBCPP_STD_VER <= 17
239+ #endif // _LIBCPP_STD_VER >= 20
235240
236241private:
237242 template <class >
Original file line number Diff line number Diff line change 1111//
1212// Comparison operators
1313
14+ #include < concepts>
1415#include < __iterator/bounded_iter.h>
1516
1617#include " test_iterators.h"
@@ -59,6 +60,16 @@ TEST_CONSTEXPR_CXX14 bool tests() {
5960 assert (iter1 >= iter1);
6061 }
6162
63+ #if TEST_STD_VER >= 20
64+ if constexpr (requires (std::__bounded_iter<Iter> const iter) {
65+ { iter <=> iter } -> std::same_as<std::strong_ordering>;
66+ }) {
67+ // P1614
68+ std::same_as<std::strong_ordering> decltype (auto ) r1 = iter1 <=> iter2;
69+ assert (r1 == std::strong_ordering::less);
70+ }
71+ #endif
72+
6273 return true ;
6374}
6475
@@ -69,8 +80,11 @@ int main(int, char**) {
6980#endif
7081
7182#if TEST_STD_VER > 17
72- tests<contiguous_iterator<int *> >();
73- static_assert (tests<contiguous_iterator<int *> >(), " " );
83+ tests<contiguous_iterator<int *>>();
84+ static_assert (tests<contiguous_iterator<int *>>());
85+
86+ tests<three_way_contiguous_iterator<int *>>();
87+ static_assert (tests<three_way_contiguous_iterator<int *>>());
7488#endif
7589
7690 return 0 ;
Original file line number Diff line number Diff line change 1212
1313// class iterator
1414
15- #include < span>
1615#include < cassert>
16+ #include < concepts>
17+ #include < span>
1718#include < string>
1819#include < version> // __cpp_lib_ranges_as_const is not defined in span.
1920
Original file line number Diff line number Diff line change 1212
1313// class iterator
1414
15- #include < string_view>
1615#include < cassert>
16+ #include < concepts>
1717#include < iterator>
18+ #include < string_view>
1819
1920#include " test_macros.h"
2021#include " make_string.h"
Original file line number Diff line number Diff line change @@ -389,6 +389,8 @@ class contiguous_iterator
389389 friend TEST_CONSTEXPR bool operator > (const contiguous_iterator& x, const contiguous_iterator& y) {return x.it_ > y.it_ ;}
390390 friend TEST_CONSTEXPR bool operator >=(const contiguous_iterator& x, const contiguous_iterator& y) {return x.it_ >= y.it_ ;}
391391
392+ // Note no operator<=>, use three_way_contiguous_iterator for testing operator<=>
393+
392394 friend TEST_CONSTEXPR It base (const contiguous_iterator& i) { return i.it_ ; }
393395
394396 template <class T >
You can’t perform that action at this time.
0 commit comments