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
5 files changed +32
-9
lines changed Original file line number Diff line number Diff line change @@ -202,7 +202,7 @@ struct __bounded_iter {
202
202
operator ==(__bounded_iter const & __x, __bounded_iter const & __y) _NOEXCEPT {
203
203
return __x.__current_ == __y.__current_ ;
204
204
}
205
- # if _LIBCPP_STD_VER <= 17
205
+
206
206
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR friend bool
207
207
operator !=(__bounded_iter const & __x, __bounded_iter const & __y) _NOEXCEPT {
208
208
return __x.__current_ != __y.__current_ ;
@@ -224,14 +224,19 @@ struct __bounded_iter {
224
224
return __x.__current_ >= __y.__current_ ;
225
225
}
226
226
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
+ }
229
235
_LIBCPP_HIDE_FROM_ABI constexpr friend strong_ordering
230
236
operator <=>(__bounded_iter const & __x, __bounded_iter const & __y) noexcept {
231
237
return __x.__current_ <=> __y.__current_ ;
232
238
}
233
-
234
- #endif // _LIBCPP_STD_VER <= 17
239
+ #endif // _LIBCPP_STD_VER >= 20
235
240
236
241
private:
237
242
template <class >
Original file line number Diff line number Diff line change 11
11
//
12
12
// Comparison operators
13
13
14
+ #include < concepts>
14
15
#include < __iterator/bounded_iter.h>
15
16
16
17
#include " test_iterators.h"
@@ -59,6 +60,16 @@ TEST_CONSTEXPR_CXX14 bool tests() {
59
60
assert (iter1 >= iter1);
60
61
}
61
62
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
+
62
73
return true ;
63
74
}
64
75
@@ -69,8 +80,11 @@ int main(int, char**) {
69
80
#endif
70
81
71
82
#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 *>>());
74
88
#endif
75
89
76
90
return 0 ;
Original file line number Diff line number Diff line change 12
12
13
13
// class iterator
14
14
15
- #include < span>
16
15
#include < cassert>
16
+ #include < concepts>
17
+ #include < span>
17
18
#include < string>
18
19
#include < version> // __cpp_lib_ranges_as_const is not defined in span.
19
20
Original file line number Diff line number Diff line change 12
12
13
13
// class iterator
14
14
15
- #include < string_view>
16
15
#include < cassert>
16
+ #include < concepts>
17
17
#include < iterator>
18
+ #include < string_view>
18
19
19
20
#include " test_macros.h"
20
21
#include " make_string.h"
Original file line number Diff line number Diff line change @@ -389,6 +389,8 @@ class contiguous_iterator
389
389
friend TEST_CONSTEXPR bool operator > (const contiguous_iterator& x, const contiguous_iterator& y) {return x.it_ > y.it_ ;}
390
390
friend TEST_CONSTEXPR bool operator >=(const contiguous_iterator& x, const contiguous_iterator& y) {return x.it_ >= y.it_ ;}
391
391
392
+ // Note no operator<=>, use three_way_contiguous_iterator for testing operator<=>
393
+
392
394
friend TEST_CONSTEXPR It base (const contiguous_iterator& i) { return i.it_ ; }
393
395
394
396
template <class T >
You can’t perform that action at this time.
0 commit comments