Skip to content

Commit 635c6ec

Browse files
committed
[libc++][spaceship] Implements X::iterator container requirements.
This implements the requirements for the container iterator requirements for array, deque, vector, and vector<bool>. Implements: - LWG3352 strong_equality isn't a thing Implements parts of: - P1614R2 The Mothership has Landed Fixes: #62486
1 parent daab6fc commit 635c6ec

File tree

9 files changed

+92
-3
lines changed

9 files changed

+92
-3
lines changed

libcxx/docs/Status/Cxx20Issues.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@
264264
"`3349 <https://wg21.link/LWG3349>`__","Missing ``__cpp_lib_constexpr_complex``\ for P0415R1","Prague","|Complete|","16.0"
265265
"`3350 <https://wg21.link/LWG3350>`__","Simplify return type of ``lexicographical_compare_three_way``\ ","Prague","|Complete|","17.0","|spaceship|"
266266
"`3351 <https://wg21.link/LWG3351>`__","``ranges::enable_safe_range``\ should not be constrained","Prague","|Complete|","15.0","|ranges|"
267-
"`3352 <https://wg21.link/LWG3352>`__","``strong_equality``\ isn't a thing","Prague","|Nothing To Do|","","|spaceship|"
267+
"`3352 <https://wg21.link/LWG3352>`__","``strong_equality``\ isn't a thing","Prague","|Complete|","19.0","|spaceship|"
268268
"`3354 <https://wg21.link/LWG3354>`__","``has_strong_structural_equality``\ has a meaningless definition","Prague","|Nothing To Do|","","|spaceship|"
269269
"`3355 <https://wg21.link/LWG3355>`__","The memory algorithms should support move-only input iterators introduced by P1207","Prague","|Complete|","15.0","|ranges|"
270270
"`3356 <https://wg21.link/LWG3356>`__","``__cpp_lib_nothrow_convertible``\ should be ``__cpp_lib_is_nothrow_convertible``\ ","Prague","|Complete|","12.0"

libcxx/docs/Status/SpaceshipProjects.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Section,Description,Dependencies,Assignee,Complete
8383
"| `[string.view.synop] <https://wg21.link/string.view.synop>`_
8484
| `[string.view.comparison] <https://wg21.link/string.view.comparison>`_",| `basic_string_view <https://reviews.llvm.org/D130295>`_,None,Mark de Wever,|Complete|
8585
- `5.7 Clause 22: Containers library <https://wg21.link/p1614r2#clause-22-containers-library>`_,,,,
86-
| `[container.requirements.general] <https://wg21.link/container.requirements.general>`_,|,None,Unassigned,|Not Started|
86+
| `[container.requirements.general] <https://wg21.link/container.requirements.general>`_,|,None,Mark de Wever,|Complete|
8787
| `[array.syn] <https://wg21.link/array.syn>`_ (`general <https://wg21.link/container.opt.reqmts>`_),| `array <https://reviews.llvm.org/D132265>`_,[expos.only.func],"| Adrian Vogelsgesang
8888
| Hristo Hristov",|Complete|
8989
| `[deque.syn] <https://wg21.link/deque.syn>`_ (`general <https://wg21.link/container.opt.reqmts>`_),| `deque <https://reviews.llvm.org/D144821>`_,[expos.only.func],Hristo Hristov,|Complete|

libcxx/include/__bit_reference

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <__bit/countr.h>
1717
#include <__bit/invert_if.h>
1818
#include <__bit/popcount.h>
19+
#include <__compare/strong_order.h>
1920
#include <__config>
2021
#include <__fwd/bit_reference.h>
2122
#include <__iterator/iterator_traits.h>
@@ -913,6 +914,7 @@ public:
913914
return __x.__seg_ == __y.__seg_ && __x.__ctz_ == __y.__ctz_;
914915
}
915916

917+
#if _LIBCPP_STD_VER <= 17
916918
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 friend bool
917919
operator!=(const __bit_iterator& __x, const __bit_iterator& __y) {
918920
return !(__x == __y);
@@ -937,6 +939,18 @@ public:
937939
operator>=(const __bit_iterator& __x, const __bit_iterator& __y) {
938940
return !(__x < __y);
939941
}
942+
#else // _LIBCPP_STD_VER <= 17
943+
_LIBCPP_HIDE_FROM_ABI constexpr friend strong_ordering
944+
operator<=>(const __bit_iterator& __x, const __bit_iterator& __y) {
945+
if (__x.__seg_ < __y.__seg_)
946+
return strong_ordering::less;
947+
948+
if (__x.__seg_ == __y.__seg_)
949+
return __x.__ctz_ <=> __y.__ctz_;
950+
951+
return strong_ordering::greater;
952+
}
953+
#endif // _LIBCPP_STD_VER <= 17
940954

941955
private:
942956
_LIBCPP_HIDE_FROM_ABI

libcxx/include/__iterator/wrap_iter.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#ifndef _LIBCPP___ITERATOR_WRAP_ITER_H
1111
#define _LIBCPP___ITERATOR_WRAP_ITER_H
1212

13+
#include <__compare/strong_order.h>
1314
#include <__config>
1415
#include <__iterator/iterator_traits.h>
1516
#include <__memory/addressof.h>
@@ -119,6 +120,8 @@ operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEX
119120
return __x.base() == __y.base();
120121
}
121122

123+
#if _LIBCPP_STD_VER <= 17
124+
122125
template <class _Iter1>
123126
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
124127
operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT {
@@ -179,6 +182,22 @@ operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEX
179182
return !(__y < __x);
180183
}
181184

185+
#else // _LIBCPP_STD_VER <= 17
186+
187+
template <class _Iter1>
188+
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering
189+
operator<=>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) noexcept {
190+
return __x.base() <=> __y.base();
191+
}
192+
193+
template <class _Iter1, class _Iter2>
194+
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering
195+
operator<=>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) noexcept {
196+
return __x.base() <=> __y.base();
197+
}
198+
199+
#endif // _LIBCPP_STD_VER <= 17
200+
182201
template <class _Iter1, class _Iter2>
183202
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
184203
#ifndef _LIBCPP_CXX03_LANG

libcxx/include/deque

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

379+
#if _LIBCPP_STD_VER <= 17
379380
_LIBCPP_HIDE_FROM_ABI friend bool operator!=(const __deque_iterator& __x, const __deque_iterator& __y) {
380381
return !(__x == __y);
381382
}
@@ -395,6 +396,17 @@ public:
395396
_LIBCPP_HIDE_FROM_ABI friend bool operator>=(const __deque_iterator& __x, const __deque_iterator& __y) {
396397
return !(__x < __y);
397398
}
399+
#else // _LIBCPP_STD_VER <= 17
400+
_LIBCPP_HIDE_FROM_ABI friend strong_ordering operator<=>(const __deque_iterator& __x, const __deque_iterator& __y) {
401+
if (__x.__m_iter_ < __y.__m_iter_)
402+
return strong_ordering::less;
403+
404+
if (__x.__m_iter_ == __y.__m_iter_)
405+
return __x.__ptr_ <=> __y.__ptr_;
406+
407+
return strong_ordering::greater;
408+
}
409+
#endif // _LIBCPP_STD_VER <= 17
398410

399411
private:
400412
_LIBCPP_HIDE_FROM_ABI explicit __deque_iterator(__map_iterator __m, pointer __p) _NOEXCEPT

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,15 @@ TEST_CONSTEXPR_CXX17 bool tests()
148148
assert(std::rbegin(c) != std::rend(c));
149149
assert(std::cbegin(c) != std::cend(c));
150150
assert(std::crbegin(c) != std::crend(c));
151+
152+
# if TEST_STD_VER >= 20
153+
// P1614 + LWG3352
154+
std::same_as<std::strong_ordering> decltype(auto) r1 = ii1 <=> ii2;
155+
assert(r1 == std::strong_ordering::equal);
156+
157+
std::same_as<std::strong_ordering> decltype(auto) r2 = ii1 <=> ii2;
158+
assert(r2 == std::strong_ordering::equal);
159+
# endif
151160
}
152161
{
153162
typedef std::array<int, 0> C;
@@ -189,6 +198,15 @@ TEST_CONSTEXPR_CXX17 bool tests()
189198
assert(std::rbegin(c) == std::rend(c));
190199
assert(std::cbegin(c) == std::cend(c));
191200
assert(std::crbegin(c) == std::crend(c));
201+
202+
# if TEST_STD_VER >= 20
203+
// P1614 + LWG3352
204+
std::same_as<std::strong_ordering> decltype(auto) r1 = ii1 <=> ii2;
205+
assert(r1 == std::strong_ordering::equal);
206+
207+
std::same_as<std::strong_ordering> decltype(auto) r2 = ii1 <=> ii2;
208+
assert(r2 == std::strong_ordering::equal);
209+
# endif
192210
}
193211
}
194212
#endif

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ int main(int, char**)
7474
// assert ( cii != c.begin());
7575
// assert ( cii != c.cend());
7676
// assert ( ii1 != c.end());
77+
78+
# if TEST_STD_VER >= 20
79+
// P1614 + LWG3352
80+
std::same_as<std::strong_ordering> decltype(auto) r1 = ii1 <=> ii2;
81+
assert(r1 == std::strong_ordering::equal);
82+
83+
std::same_as<std::strong_ordering> decltype(auto) r2 = ii1 <=> ii2;
84+
assert(r2 == std::strong_ordering::equal);
85+
# endif // TEST_STD_VER > 20
7786
}
7887
#endif
7988

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@ TEST_CONSTEXPR_CXX20 bool tests()
131131
assert ( (cii >= ii1 ));
132132
assert (cii - ii1 == 0);
133133
assert (ii1 - cii == 0);
134+
135+
# if TEST_STD_VER >= 20
136+
// P1614 + LWG3352
137+
std::same_as<std::strong_ordering> decltype(auto) r1 = ii1 <=> ii2;
138+
assert(r1 == std::strong_ordering::equal);
139+
140+
std::same_as<std::strong_ordering> decltype(auto) r2 = ii1 <=> ii2;
141+
assert(r2 == std::strong_ordering::equal);
142+
# endif // TEST_STD_VER > 20
134143
}
135144
#endif
136145

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,16 @@ TEST_CONSTEXPR_CXX20 bool tests()
164164
assert ( (cii >= ii1 ));
165165
assert (cii - ii1 == 0);
166166
assert (ii1 - cii == 0);
167+
# if TEST_STD_VER >= 20
168+
// P1614 + LWG3352
169+
std::same_as<std::strong_ordering> decltype(auto) r1 = ii1 <=> ii2;
170+
assert(r1 == std::strong_ordering::equal);
171+
172+
std::same_as<std::strong_ordering> decltype(auto) r2 = ii1 <=> ii2;
173+
assert(r2 == std::strong_ordering::equal);
174+
# endif // TEST_STD_VER > 20
167175
}
168-
#endif
176+
#endif // TEST_STD_VER > 11
169177

170178
return true;
171179
}

0 commit comments

Comments
 (0)