Skip to content

Commit 0739782

Browse files
committed
CI fixes and improvements
Note the code is not yet conforming.
1 parent cd9e497 commit 0739782

File tree

8 files changed

+104
-25
lines changed

8 files changed

+104
-25
lines changed

libcxx/include/__iterator/bounded_iter.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#include <__assert>
1414
#include <__compare/ordering.h>
15-
#include <__concepts/same_as.h>
15+
#include <__compare/three_way_comparable.h>
1616
#include <__config>
1717
#include <__iterator/iterator_traits.h>
1818
#include <__memory/pointer_traits.h>
@@ -226,15 +226,10 @@ struct __bounded_iter {
226226
}
227227

228228
#if _LIBCPP_STD_VER >= 20
229-
// It is not required that the underlying iterator supports operator<=>.
230-
// Therefore this operator is only conditionally provided, which requires a
231-
// templated function.
232-
template <class _Tp = void>
233-
requires requires(_Iterator const& __i) {
234-
{ __i <=> __i } -> same_as<strong_ordering>;
235-
}
236229
_LIBCPP_HIDE_FROM_ABI constexpr friend strong_ordering
237-
operator<=>(__bounded_iter const& __x, __bounded_iter const& __y) noexcept {
230+
operator<=>(__bounded_iter const& __x, __bounded_iter const& __y) noexcept
231+
requires three_way_comparable<_Iterator, strong_ordering>
232+
{
238233
return __x.__current_ <=> __y.__current_;
239234
}
240235
#endif // _LIBCPP_STD_VER >= 20

libcxx/include/__iterator/wrap_iter.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define _LIBCPP___ITERATOR_WRAP_ITER_H
1212

1313
#include <__compare/ordering.h>
14+
#include <__compare/three_way_comparable.h>
1415
#include <__config>
1516
#include <__iterator/iterator_traits.h>
1617
#include <__memory/addressof.h>
@@ -120,8 +121,6 @@ operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEX
120121
return __x.base() == __y.base();
121122
}
122123

123-
#if _LIBCPP_STD_VER <= 17
124-
125124
template <class _Iter1>
126125
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
127126
operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT {
@@ -182,21 +181,25 @@ operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEX
182181
return !(__y < __x);
183182
}
184183

185-
#else // _LIBCPP_STD_VER <= 17
184+
#if _LIBCPP_STD_VER >= 20
186185

187186
template <class _Iter1>
188187
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering
189-
operator<=>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) noexcept {
188+
operator<=>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) noexcept
189+
requires three_way_comparable<_Iter1, strong_ordering>
190+
{
190191
return __x.base() <=> __y.base();
191192
}
192193

193194
template <class _Iter1, class _Iter2>
194195
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering
195-
operator<=>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) noexcept {
196+
operator<=>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) noexcept
197+
requires three_way_comparable_with<_Iter1, _Iter2, strong_ordering>
198+
{
196199
return __x.base() <=> __y.base();
197200
}
198201

199-
#endif // _LIBCPP_STD_VER <= 17
202+
#endif // _LIBCPP_STD_VER >= 20
200203

201204
template <class _Iter1, class _Iter2>
202205
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14

libcxx/include/deque

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ public:
376376
return __x.__ptr_ == __y.__ptr_;
377377
}
378378

379-
#if _LIBCPP_STD_VER <= 17
380379
_LIBCPP_HIDE_FROM_ABI friend bool operator!=(const __deque_iterator& __x, const __deque_iterator& __y) {
381380
return !(__x == __y);
382381
}
@@ -396,8 +395,12 @@ public:
396395
_LIBCPP_HIDE_FROM_ABI friend bool operator>=(const __deque_iterator& __x, const __deque_iterator& __y) {
397396
return !(__x < __y);
398397
}
399-
#else // _LIBCPP_STD_VER <= 17
400-
_LIBCPP_HIDE_FROM_ABI friend strong_ordering operator<=>(const __deque_iterator& __x, const __deque_iterator& __y) {
398+
399+
#if _LIBCPP_STD_VER >= 20
400+
// template <class _Tp = void>
401+
_LIBCPP_HIDE_FROM_ABI friend strong_ordering operator<=>(const __deque_iterator& __x, const __deque_iterator& __y)
402+
requires three_way_comparable<pointer, strong_ordering>
403+
{
401404
if (__x.__m_iter_ < __y.__m_iter_)
402405
return strong_ordering::less;
403406

@@ -406,7 +409,7 @@ public:
406409

407410
return strong_ordering::greater;
408411
}
409-
#endif // _LIBCPP_STD_VER <= 17
412+
#endif // _LIBCPP_STD_VER >= 20
410413

411414
private:
412415
_LIBCPP_HIDE_FROM_ABI explicit __deque_iterator(__map_iterator __m, pointer __p) _NOEXCEPT

libcxx/test/std/containers/sequences/array/iterators.pass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ TEST_CONSTEXPR_CXX17 bool tests()
154154
std::same_as<std::strong_ordering> decltype(auto) r1 = ii1 <=> ii2;
155155
assert(r1 == std::strong_ordering::equal);
156156

157-
std::same_as<std::strong_ordering> decltype(auto) r2 = ii1 <=> ii2;
157+
std::same_as<std::strong_ordering> decltype(auto) r2 = cii <=> ii2;
158158
assert(r2 == std::strong_ordering::equal);
159159
# endif
160160
}
@@ -204,7 +204,7 @@ TEST_CONSTEXPR_CXX17 bool tests()
204204
std::same_as<std::strong_ordering> decltype(auto) r1 = ii1 <=> ii2;
205205
assert(r1 == std::strong_ordering::equal);
206206

207-
std::same_as<std::strong_ordering> decltype(auto) r2 = ii1 <=> ii2;
207+
std::same_as<std::strong_ordering> decltype(auto) r2 = cii <=> ii2;
208208
assert(r2 == std::strong_ordering::equal);
209209
# endif
210210
}

libcxx/test/std/containers/sequences/deque/iterators.pass.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,23 @@ int main(int, char**)
4141
i = c.begin();
4242
C::const_iterator j;
4343
j = c.cbegin();
44+
4445
assert(i == j);
46+
assert(!(i != j));
47+
48+
assert(!(i < j));
49+
assert((i <= j));
50+
51+
assert(!(i > j));
52+
assert((i >= j));
53+
54+
# if TEST_STD_VER >= 20
55+
// P1614 + LWG3352
56+
// When the allocator does not have operator<=> then neither does the iterator.
57+
// Make sure to test with an allocator that does not have operator<=>.
58+
static_assert(!std::three_way_comparable<min_allocator<int>, std::strong_ordering>);
59+
static_assert(!std::three_way_comparable<typename C::iterator, std::strong_ordering>);
60+
# endif
4561
}
4662
#endif
4763
#if TEST_STD_VER > 11
@@ -80,7 +96,7 @@ int main(int, char**)
8096
std::same_as<std::strong_ordering> decltype(auto) r1 = ii1 <=> ii2;
8197
assert(r1 == std::strong_ordering::equal);
8298

83-
std::same_as<std::strong_ordering> decltype(auto) r2 = ii1 <=> ii2;
99+
std::same_as<std::strong_ordering> decltype(auto) r2 = cii <=> ii2;
84100
assert(r2 == std::strong_ordering::equal);
85101
# endif // TEST_STD_VER > 20
86102
}

libcxx/test/std/containers/sequences/vector.bool/iterators.pass.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,21 @@ TEST_CONSTEXPR_CXX20 bool tests()
7777
C::iterator i = c.begin();
7878
C::iterator j = c.end();
7979
assert(std::distance(i, j) == 0);
80+
8081
assert(i == j);
82+
assert(!(i != j));
83+
84+
assert(!(i < j));
85+
assert((i <= j));
86+
87+
assert(!(i > j));
88+
assert((i >= j));
89+
90+
# if TEST_STD_VER >= 20
91+
// P1614 + LWG3352
92+
std::same_as<std::strong_ordering> decltype(auto) r = i <=> j;
93+
assert(r == std::strong_ordering::equal);
94+
# endif
8195
}
8296
{
8397
typedef bool T;
@@ -86,7 +100,21 @@ TEST_CONSTEXPR_CXX20 bool tests()
86100
C::const_iterator i = c.begin();
87101
C::const_iterator j = c.end();
88102
assert(std::distance(i, j) == 0);
103+
89104
assert(i == j);
105+
assert(!(i != j));
106+
107+
assert(!(i < j));
108+
assert((i <= j));
109+
110+
assert(!(i > j));
111+
assert((i >= j));
112+
113+
# if TEST_STD_VER >= 20
114+
// P1614 + LWG3352
115+
std::same_as<std::strong_ordering> decltype(auto) r = i <=> j;
116+
assert(r == std::strong_ordering::equal);
117+
# endif
90118
}
91119
{
92120
typedef bool T;
@@ -137,7 +165,7 @@ TEST_CONSTEXPR_CXX20 bool tests()
137165
std::same_as<std::strong_ordering> decltype(auto) r1 = ii1 <=> ii2;
138166
assert(r1 == std::strong_ordering::equal);
139167

140-
std::same_as<std::strong_ordering> decltype(auto) r2 = ii1 <=> ii2;
168+
std::same_as<std::strong_ordering> decltype(auto) r2 = cii <=> ii2;
141169
assert(r2 == std::strong_ordering::equal);
142170
# endif // TEST_STD_VER > 20
143171
}

libcxx/test/std/containers/sequences/vector/iterators.pass.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,23 @@ TEST_CONSTEXPR_CXX20 bool tests()
8787
C::iterator i = c.begin();
8888
C::iterator j = c.end();
8989
assert(std::distance(i, j) == 0);
90+
9091
assert(i == j);
92+
assert(!(i != j));
93+
94+
assert(!(i < j));
95+
assert((i <= j));
96+
97+
assert(!(i > j));
98+
assert((i >= j));
99+
100+
# if TEST_STD_VER >= 20
101+
// P1614 + LWG3352
102+
// When the allocator does not have operator<=> then neither does the iterator.
103+
// Make sure to test with an allocator that does not have operator<=>.
104+
static_assert(!std::three_way_comparable<min_allocator<int>, std::strong_ordering>);
105+
static_assert(!std::three_way_comparable<typename C::iterator, std::strong_ordering>);
106+
# endif
91107
}
92108
{
93109
typedef int T;
@@ -96,7 +112,23 @@ TEST_CONSTEXPR_CXX20 bool tests()
96112
C::const_iterator i = c.begin();
97113
C::const_iterator j = c.end();
98114
assert(std::distance(i, j) == 0);
115+
99116
assert(i == j);
117+
assert(!(i != j));
118+
119+
assert(!(i < j));
120+
assert((i <= j));
121+
122+
assert(!(i > j));
123+
assert((i >= j));
124+
125+
# if TEST_STD_VER >= 20
126+
// P1614 + LWG3352
127+
// When the allocator does not have operator<=> then neither does the iterator.
128+
// Make sure to test with an allocator that does not have operator<=>.
129+
static_assert(!std::three_way_comparable<min_allocator<int>, std::strong_ordering>);
130+
static_assert(!std::three_way_comparable<typename C::iterator, std::strong_ordering>);
131+
# endif
100132
}
101133
{
102134
typedef int T;
@@ -169,7 +201,7 @@ TEST_CONSTEXPR_CXX20 bool tests()
169201
std::same_as<std::strong_ordering> decltype(auto) r1 = ii1 <=> ii2;
170202
assert(r1 == std::strong_ordering::equal);
171203

172-
std::same_as<std::strong_ordering> decltype(auto) r2 = ii1 <=> ii2;
204+
std::same_as<std::strong_ordering> decltype(auto) r2 = cii <=> ii2;
173205
assert(r2 == std::strong_ordering::equal);
174206
# endif // TEST_STD_VER > 20
175207
}

libcxx/test/std/containers/views/views.span/span.iterators/iterator.pass.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ TEST_CONSTEXPR void test_type() {
7171
std::same_as<std::strong_ordering> decltype(auto) r1 = ii1 <=> ii2;
7272
assert(r1 == std::strong_ordering::equal);
7373

74-
std::same_as<std::strong_ordering> decltype(auto) r2 = ii1 <=> ii2;
74+
#ifdef __cpp_lib_ranges_as_const
75+
std::same_as<std::strong_ordering> decltype(auto) r2 = cii <=> ii2;
7576
assert(r2 == std::strong_ordering::equal);
77+
#endif
7678
}
7779

7880
TEST_CONSTEXPR bool test() {

0 commit comments

Comments
 (0)