Skip to content

Commit 81aff9b

Browse files
ahanamukStephanTLavavej
authored andcommitted
Container spaceship changes, squashed.
1 parent 8fcc25f commit 81aff9b

File tree

16 files changed

+380
-0
lines changed

16 files changed

+380
-0
lines changed

stl/inc/array

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,10 @@ public:
577577
return _Elems;
578578
}
579579

580+
// friend constexpr bool operator==(const array&, const array&) = default;
581+
// friend constexpr _Synth_three_way_result<value_type> operator<=>(const array&, const array&);
582+
// friend constexpr bool operator<=>(const array&, const array&);
583+
580584
[[noreturn]] void _Xran() const {
581585
_Xout_of_range("invalid array<T, N> subscript");
582586
}
@@ -778,6 +782,7 @@ _NODISCARD _CONSTEXPR20 bool operator==(const array<_Ty, _Size>& _Left, const ar
778782
return _STD equal(_Left.begin(), _Left.end(), _Right.begin());
779783
}
780784

785+
#if !_HAS_CXX20 || __cpp_impl_three_way_comparison < 201902L
781786
template <class _Ty, size_t _Size>
782787
_NODISCARD _CONSTEXPR20 bool operator!=(const array<_Ty, _Size>& _Left, const array<_Ty, _Size>& _Right) {
783788
return !(_Left == _Right);
@@ -802,6 +807,15 @@ template <class _Ty, size_t _Size>
802807
_NODISCARD _CONSTEXPR20 bool operator>=(const array<_Ty, _Size>& _Left, const array<_Ty, _Size>& _Right) {
803808
return !(_Left < _Right);
804809
}
810+
#endif // !_HAS_CXX20 || __cpp_impl_three_way_comparison < 201902L
811+
812+
#if defined(__cpp_impl_three_way_comparison) && defined(__cpp_lib_concepts)
813+
template <class _Ty, size_t _Size>
814+
_NODISCARD _CONSTEXPR20 _Synth_three_way_result<_Ty> operator<=>(
815+
const array<_Ty, _Size>& _Left, const array<_Ty, _Size>& _Right) {
816+
return _STD lexicographical_compare_three_way(_Left.begin(), _Left.end(), _Right.begin(), _Right.end());
817+
}
818+
#endif // defined(__cpp_impl_three_way_comparison) && defined(__cpp_lib_concepts)
805819

806820
#if _HAS_CXX20
807821
// FUNCTION TEMPLATE to_array

stl/inc/deque

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,7 @@ _NODISCARD bool operator==(const deque<_Ty, _Alloc>& _Left, const deque<_Ty, _Al
15811581
&& _STD equal(_Left._Unchecked_begin(), _Left._Unchecked_end(), _Right._Unchecked_begin());
15821582
}
15831583

1584+
#if !_HAS_CXX20 || __cpp_impl_three_way_comparison < 201902L
15841585
template <class _Ty, class _Alloc>
15851586
_NODISCARD bool operator!=(const deque<_Ty, _Alloc>& _Left, const deque<_Ty, _Alloc>& _Right) {
15861587
return !(_Left == _Right);
@@ -1606,6 +1607,15 @@ template <class _Ty, class _Alloc>
16061607
_NODISCARD bool operator>=(const deque<_Ty, _Alloc>& _Left, const deque<_Ty, _Alloc>& _Right) {
16071608
return !(_Left < _Right);
16081609
}
1610+
#endif // !_HAS_CXX20 || __cpp_impl_three_way_comparison < 201902L
1611+
1612+
#if defined(__cpp_impl_three_way_comparison) && defined(__cpp_lib_concepts)
1613+
template <class _Ty, class _Alloc>
1614+
_NODISCARD _Synth_three_way_result<_Ty> operator<=>(const deque<_Ty, _Alloc>& _Left, const deque<_Ty, _Alloc>& _Right) {
1615+
return _STD lexicographical_compare_three_way(_Left._Unchecked_begin(), _Left._Unchecked_end(),
1616+
_Right._Unchecked_begin(), _Right._Unchecked_end(), _Synth_three_way{});
1617+
}
1618+
#endif // defined(__cpp_impl_three_way_comparison) && defined(__cpp_lib_concepts)
16091619

16101620
#if _HAS_CXX20
16111621
template <class _Ty, class _Alloc, class _Uty>

stl/inc/forward_list

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,7 @@ _NODISCARD bool operator==(const forward_list<_Ty, _Alloc>& _Left, const forward
15211521
return _STD equal(_Left.begin(), _Left.end(), _Right.begin(), _Right.end());
15221522
}
15231523

1524+
#if !_HAS_CXX20 || __cpp_impl_three_way_comparison < 201902L
15241525
template <class _Ty, class _Alloc>
15251526
_NODISCARD bool operator!=(const forward_list<_Ty, _Alloc>& _Left, const forward_list<_Ty, _Alloc>& _Right) {
15261527
return !(_Left == _Right);
@@ -1545,6 +1546,16 @@ template <class _Ty, class _Alloc>
15451546
_NODISCARD bool operator>=(const forward_list<_Ty, _Alloc>& _Left, const forward_list<_Ty, _Alloc>& _Right) {
15461547
return !(_Left < _Right);
15471548
}
1549+
#endif // !_HAS_CXX20 || __cpp_impl_three_way_comparison < 201902L
1550+
1551+
#if defined(__cpp_impl_three_way_comparison) && defined(__cpp_lib_concepts)
1552+
template <class _Ty, class _Alloc>
1553+
_NODISCARD _Synth_three_way_result<_Ty> operator<=>(
1554+
const forward_list<_Ty, _Alloc>& _Left, const forward_list<_Ty, _Alloc>& _Right) {
1555+
return _STD lexicographical_compare_three_way(
1556+
_Left.begin(), _Left.end(), _Right.begin(), _Right.end(), _Synth_three_way{});
1557+
}
1558+
#endif // defined(__cpp_impl_three_way_comparison) && defined(__cpp_lib_concepts)
15481559

15491560
#if _HAS_CXX20
15501561
template <class _Ty, class _Alloc, class _Uty>

stl/inc/iterator

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,13 @@ _NODISCARD bool operator==(const istream_iterator<_Ty, _Elem, _Traits, _Diff>& _
292292
return _Left._Equal(_Right);
293293
}
294294

295+
#if !_HAS_CXX20 || __cpp_impl_three_way_comparison < 201902L
295296
template <class _Ty, class _Elem, class _Traits, class _Diff>
296297
_NODISCARD bool operator!=(const istream_iterator<_Ty, _Elem, _Traits, _Diff>& _Left,
297298
const istream_iterator<_Ty, _Elem, _Traits, _Diff>& _Right) {
298299
return !(_Left == _Right);
299300
}
301+
#endif // !_HAS_CXX20 || __cpp_impl_three_way_comparison < 201902L
300302

301303
// CLASS TEMPLATE ostream_iterator
302304
template <class _Ty, class _Elem = char, class _Traits = char_traits<_Elem>>
@@ -458,11 +460,13 @@ _NODISCARD bool operator==(
458460
return _Left.equal(_Right);
459461
}
460462

463+
#if !_HAS_CXX20 || __cpp_impl_three_way_comparison < 201902L
461464
template <class _Elem, class _Traits>
462465
_NODISCARD bool operator!=(
463466
const istreambuf_iterator<_Elem, _Traits>& _Left, const istreambuf_iterator<_Elem, _Traits>& _Right) {
464467
return !(_Left == _Right);
465468
}
469+
#endif // !_HAS_CXX20 || __cpp_impl_three_way_comparison < 201902L
466470

467471
// CLASS TEMPLATE ostreambuf_iterator
468472
template <class _Elem, class _Traits>

stl/inc/list

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,6 +1810,7 @@ _NODISCARD bool operator==(const list<_Ty, _Alloc>& _Left, const list<_Ty, _Allo
18101810
return _Left.size() == _Right.size() && _STD equal(_Left.begin(), _Left.end(), _Right.begin());
18111811
}
18121812

1813+
#if !_HAS_CXX20 || __cpp_impl_three_way_comparison < 201902L
18131814
template <class _Ty, class _Alloc>
18141815
_NODISCARD bool operator!=(const list<_Ty, _Alloc>& _Left, const list<_Ty, _Alloc>& _Right) {
18151816
return !(_Left == _Right);
@@ -1834,6 +1835,15 @@ template <class _Ty, class _Alloc>
18341835
_NODISCARD bool operator>=(const list<_Ty, _Alloc>& _Left, const list<_Ty, _Alloc>& _Right) {
18351836
return !(_Left < _Right);
18361837
}
1838+
#endif // !_HAS_CXX20 || __cpp_impl_three_way_comparison < 201902L
1839+
1840+
#if defined(__cpp_impl_three_way_comparison) && defined(__cpp_lib_concepts)
1841+
template <class _Ty, class _Alloc>
1842+
_NODISCARD _Synth_three_way_result<_Ty> operator<=>(const list<_Ty, _Alloc>& _Left, const list<_Ty, _Alloc>& _Right) {
1843+
return _STD lexicographical_compare_three_way(
1844+
_Left.begin(), _Left.end(), _Right.begin(), _Right.end(), _Synth_three_way{});
1845+
}
1846+
#endif // defined(__cpp_impl_three_way_comparison) && defined(__cpp_lib_concepts)
18371847

18381848
#if _HAS_CXX20
18391849
template <class _Ty, class _Alloc, class _Uty>

stl/inc/map

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ _NODISCARD bool operator==(const map<_Kty, _Ty, _Pr, _Alloc>& _Left, const map<_
369369
&& _STD equal(_Left._Unchecked_begin(), _Left._Unchecked_end_iter(), _Right._Unchecked_begin());
370370
}
371371

372+
#if !_HAS_CXX20 || __cpp_impl_three_way_comparison < 201902L
372373
template <class _Kty, class _Ty, class _Pr, class _Alloc>
373374
_NODISCARD bool operator!=(const map<_Kty, _Ty, _Pr, _Alloc>& _Left, const map<_Kty, _Ty, _Pr, _Alloc>& _Right) {
374375
return !(_Left == _Right);
@@ -394,6 +395,16 @@ template <class _Kty, class _Ty, class _Pr, class _Alloc>
394395
_NODISCARD bool operator>=(const map<_Kty, _Ty, _Pr, _Alloc>& _Left, const map<_Kty, _Ty, _Pr, _Alloc>& _Right) {
395396
return !(_Left < _Right);
396397
}
398+
#endif // !_HAS_CXX20 || __cpp_impl_three_way_comparison < 201902L
399+
400+
#if defined(__cpp_impl_three_way_comparison) && defined(__cpp_lib_concepts)
401+
template <class _Kty, class _Ty, class _Pr, class _Alloc>
402+
_NODISCARD _Synth_three_way_result<pair<const _Kty, _Ty>> operator<=>(
403+
const map<_Kty, _Ty, _Pr, _Alloc>& _Left, const map<_Kty, _Ty, _Pr, _Alloc>& _Right) {
404+
return _STD lexicographical_compare_three_way(_Left._Unchecked_begin(), _Left._Unchecked_end_iter(),
405+
_Right._Unchecked_begin(), _Right._Unchecked_end_iter(), _Synth_three_way{});
406+
}
407+
#endif // defined(__cpp_impl_three_way_comparison) && defined(__cpp_lib_concepts)
397408

398409
template <class _Kty, class _Ty, class _Pr, class _Alloc>
399410
void swap(map<_Kty, _Ty, _Pr, _Alloc>& _Left, map<_Kty, _Ty, _Pr, _Alloc>& _Right) noexcept(
@@ -557,6 +568,7 @@ _NODISCARD bool operator==(
557568
&& _STD equal(_Left._Unchecked_begin(), _Left._Unchecked_end_iter(), _Right._Unchecked_begin());
558569
}
559570

571+
#if !_HAS_CXX20 || __cpp_impl_three_way_comparison < 201902L
560572
template <class _Kty, class _Ty, class _Pr, class _Alloc>
561573
_NODISCARD bool operator!=(
562574
const multimap<_Kty, _Ty, _Pr, _Alloc>& _Left, const multimap<_Kty, _Ty, _Pr, _Alloc>& _Right) {
@@ -587,6 +599,16 @@ _NODISCARD bool operator>=(
587599
const multimap<_Kty, _Ty, _Pr, _Alloc>& _Left, const multimap<_Kty, _Ty, _Pr, _Alloc>& _Right) {
588600
return !(_Left < _Right);
589601
}
602+
#endif // !_HAS_CXX20 || __cpp_impl_three_way_comparison < 201902L
603+
604+
#if defined(__cpp_impl_three_way_comparison) && defined(__cpp_lib_concepts)
605+
template <class _Kty, class _Ty, class _Pr, class _Alloc>
606+
_NODISCARD _Synth_three_way_result<pair<const _Kty, _Ty>> operator<=>(
607+
const multimap<_Kty, _Ty, _Pr, _Alloc>& _Left, const multimap<_Kty, _Ty, _Pr, _Alloc>& _Right) {
608+
return _STD lexicographical_compare_three_way(_Left._Unchecked_begin(), _Left._Unchecked_end_iter(),
609+
_Right._Unchecked_begin(), _Right._Unchecked_end_iter(), _Synth_three_way{});
610+
}
611+
#endif // defined(__cpp_impl_three_way_comparison) && defined(__cpp_lib_concepts)
590612

591613
template <class _Kty, class _Ty, class _Pr, class _Alloc>
592614
void swap(multimap<_Kty, _Ty, _Pr, _Alloc>& _Left, multimap<_Kty, _Ty, _Pr, _Alloc>& _Right) noexcept(

stl/inc/queue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ _NODISCARD bool operator>=(const queue<_Ty, _Container>& _Left, const queue<_Ty,
5454
return _Left.c >= _Right.c;
5555
}
5656

57+
#if defined(__cpp_impl_three_way_comparison) && defined(__cpp_lib_concepts)
58+
template <class _Ty, three_way_comparable _Container>
59+
_NODISCARD compare_three_way_result_t<_Container> operator<=>(
60+
const queue<_Ty, _Container>& _Left, const queue<_Ty, _Container>& _Right) {
61+
return _Left.c <=> _Right.c;
62+
}
63+
#endif // defined(__cpp_impl_three_way_comparison) && defined(__cpp_lib_concepts)
64+
5765
template <class _Ty, class _Container>
5866
class queue {
5967
public:
@@ -148,6 +156,7 @@ public:
148156
friend bool operator> <>(const queue&, const queue&);
149157
friend bool operator<= <>(const queue&, const queue&);
150158
friend bool operator>= <>(const queue&, const queue&);
159+
friend compare_three_way_result_t<_Container> operator<=> <>(const queue&, const queue&);
151160
// clang-format on
152161

153162
protected:

stl/inc/set

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ _NODISCARD bool operator==(const set<_Kty, _Pr, _Alloc>& _Left, const set<_Kty,
180180
&& _STD equal(_Left._Unchecked_begin(), _Left._Unchecked_end_iter(), _Right._Unchecked_begin());
181181
}
182182

183+
#if !_HAS_CXX20 || __cpp_impl_three_way_comparison < 201902L
183184
template <class _Kty, class _Pr, class _Alloc>
184185
_NODISCARD bool operator!=(const set<_Kty, _Pr, _Alloc>& _Left, const set<_Kty, _Pr, _Alloc>& _Right) {
185186
return !(_Left == _Right);
@@ -205,6 +206,16 @@ template <class _Kty, class _Pr, class _Alloc>
205206
_NODISCARD bool operator>=(const set<_Kty, _Pr, _Alloc>& _Left, const set<_Kty, _Pr, _Alloc>& _Right) {
206207
return !(_Left < _Right);
207208
}
209+
#endif // !_HAS_CXX20 || __cpp_impl_three_way_comparison < 201902L
210+
211+
#if defined(__cpp_impl_three_way_comparison) && defined(__cpp_lib_concepts)
212+
template <class _Kty, class _Pr, class _Alloc>
213+
_NODISCARD _Synth_three_way_result<_Kty> operator<=>(
214+
const set<_Kty, _Pr, _Alloc>& _Left, const set<_Kty, _Pr, _Alloc>& _Right) {
215+
return _STD lexicographical_compare_three_way(_Left._Unchecked_begin(), _Left._Unchecked_end_iter(),
216+
_Right._Unchecked_begin(), _Right._Unchecked_end_iter(), _Synth_three_way{});
217+
}
218+
#endif // defined(__cpp_impl_three_way_comparison) && defined(__cpp_lib_concepts)
208219

209220
template <class _Kty, class _Pr, class _Alloc>
210221
void swap(set<_Kty, _Pr, _Alloc>& _Left, set<_Kty, _Pr, _Alloc>& _Right) noexcept(noexcept(_Left.swap(_Right))) {
@@ -352,6 +363,7 @@ _NODISCARD bool operator==(const multiset<_Kty, _Pr, _Alloc>& _Left, const multi
352363
&& _STD equal(_Left._Unchecked_begin(), _Left._Unchecked_end_iter(), _Right._Unchecked_begin());
353364
}
354365

366+
#if !_HAS_CXX20 || __cpp_impl_three_way_comparison < 201902L
355367
template <class _Kty, class _Pr, class _Alloc>
356368
_NODISCARD bool operator!=(const multiset<_Kty, _Pr, _Alloc>& _Left, const multiset<_Kty, _Pr, _Alloc>& _Right) {
357369
return !(_Left == _Right);
@@ -377,6 +389,16 @@ template <class _Kty, class _Pr, class _Alloc>
377389
_NODISCARD bool operator>=(const multiset<_Kty, _Pr, _Alloc>& _Left, const multiset<_Kty, _Pr, _Alloc>& _Right) {
378390
return !(_Left < _Right);
379391
}
392+
#endif // !_HAS_CXX20 || __cpp_impl_three_way_comparison < 201902L
393+
394+
#if defined(__cpp_impl_three_way_comparison) && defined(__cpp_lib_concepts)
395+
template <class _Kty, class _Pr, class _Alloc>
396+
_NODISCARD _Synth_three_way_result<_Kty> operator<=>(
397+
const multiset<_Kty, _Pr, _Alloc>& _Left, const multiset<_Kty, _Pr, _Alloc>& _Right) {
398+
return _STD lexicographical_compare_three_way(_Left._Unchecked_begin(), _Left._Unchecked_end_iter(),
399+
_Right._Unchecked_begin(), _Right._Unchecked_end_iter(), _Synth_three_way{});
400+
}
401+
#endif // defined(__cpp_impl_three_way_comparison) && defined(__cpp_lib_concepts)
380402

381403
template <class _Kty, class _Pr, class _Alloc>
382404
void swap(multiset<_Kty, _Pr, _Alloc>& _Left, multiset<_Kty, _Pr, _Alloc>& _Right) noexcept(

stl/inc/stack

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ _NODISCARD bool operator>=(const stack<_Ty, _Container>& _Left, const stack<_Ty,
5252
return _Left.c >= _Right.c;
5353
}
5454

55+
#if defined(__cpp_impl_three_way_comparison) && defined(__cpp_lib_concepts)
56+
template <class _Ty, three_way_comparable _Container>
57+
_NODISCARD compare_three_way_result_t<_Container> operator<=>(
58+
const stack<_Ty, _Container>& _Left, const stack<_Ty, _Container>& _Right) {
59+
return _Left.c <=> _Right.c;
60+
}
61+
#endif // defined(__cpp_impl_three_way_comparison) && defined(__cpp_lib_concepts)
62+
5563
template <class _Ty, class _Container>
5664
class stack {
5765
public:
@@ -138,6 +146,7 @@ public:
138146
friend bool operator> <>(const stack&, const stack&);
139147
friend bool operator<= <>(const stack&, const stack&);
140148
friend bool operator>= <>(const stack&, const stack&);
149+
friend compare_three_way_result_t<_Container> operator<=> <>(const stack&, const stack&);
141150
// clang-format on
142151

143152
protected:

stl/inc/unordered_map

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,11 +468,13 @@ _NODISCARD bool operator==(const unordered_map<_Kty, _Ty, _Hasher, _Keyeq, _Allo
468468
return _Hash_equal(_Left, _Right);
469469
}
470470

471+
#if !_HAS_CXX20 || __cpp_impl_three_way_comparison < 201902L
471472
template <class _Kty, class _Ty, class _Hasher, class _Keyeq, class _Alloc>
472473
_NODISCARD bool operator!=(const unordered_map<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Left,
473474
const unordered_map<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Right) {
474475
return !(_Left == _Right);
475476
}
477+
#endif // !_HAS_CXX20 || __cpp_impl_three_way_comparison < 201902L
476478

477479
// CLASS TEMPLATE unordered_multimap
478480
template <class _Kty, class _Ty, class _Hasher = hash<_Kty>, class _Keyeq = equal_to<_Kty>,
@@ -758,11 +760,13 @@ _NODISCARD bool operator==(const unordered_multimap<_Kty, _Ty, _Hasher, _Keyeq,
758760
return _Hash_equal(_Left, _Right);
759761
}
760762

763+
#if !_HAS_CXX20 || __cpp_impl_three_way_comparison < 201902L
761764
template <class _Kty, class _Ty, class _Hasher, class _Keyeq, class _Alloc>
762765
_NODISCARD bool operator!=(const unordered_multimap<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Left,
763766
const unordered_multimap<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Right) {
764767
return !(_Left == _Right);
765768
}
769+
#endif // !_HAS_CXX20 || __cpp_impl_three_way_comparison < 201902L
766770

767771
#if _HAS_TR1_NAMESPACE
768772
namespace _DEPRECATE_TR1_NAMESPACE tr1 {

0 commit comments

Comments
 (0)