Skip to content

Commit 2f54a84

Browse files
[libc++][test] Test flat_meow with proper underlying iterators (#131290)
Flat container adaptors require the iterators of underlying containers to be random access, and it is required that random access container iterators must support three-way comparison ([container.reqmts]/39 - /41). As a result, we should at least avoid testing "containers" with random access but not three-way comparable iterators for flat container adaptors. This patch adds a new class template `three_way_random_access_iterator` to `test_iterators.h` and fixes some usages of `MinSequenceContainer` with the new iterators.
1 parent b67880d commit 2f54a84

File tree

6 files changed

+236
-117
lines changed

6 files changed

+236
-117
lines changed

libcxx/test/std/containers/container.adaptors/flat.map/flat.map.iterators/iterator_comparison.pass.cpp

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ void test() {
2828
using Key = typename KeyContainer::value_type;
2929
using Value = typename ValueContainer::value_type;
3030
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
31-
using KI = typename KeyContainer::iterator;
3231
using I = M::iterator;
3332
using CI = M::const_iterator;
3433
using RI = M::reverse_iterator;
@@ -115,34 +114,32 @@ void test() {
115114
assert(cri2 >= cri2);
116115
assert(!(cri1 >= cri2));
117116

118-
if constexpr (std::three_way_comparable<KI>) {
119-
static_assert(std::three_way_comparable<I>); // ...of course the wrapped iterators still support <=>.
120-
static_assert(std::three_way_comparable<CI>);
121-
static_assert(std::three_way_comparable<RI>);
122-
static_assert(std::three_way_comparable<CRI>);
123-
static_assert(std::same_as<decltype(I() <=> I()), std::strong_ordering>);
124-
static_assert(std::same_as<decltype(I() <=> CI()), std::strong_ordering>);
125-
static_assert(std::same_as<decltype(CI() <=> CI()), std::strong_ordering>);
126-
static_assert(std::same_as<decltype(RI() <=> RI()), std::strong_ordering>);
127-
static_assert(std::same_as<decltype(RI() <=> CRI()), std::strong_ordering>);
128-
static_assert(std::same_as<decltype(CRI() <=> CRI()), std::strong_ordering>);
129-
130-
assert(i1 <=> i1 == std::strong_ordering::equivalent);
131-
assert(i1 <=> i2 == std::strong_ordering::less);
132-
assert(i2 <=> i1 == std::strong_ordering::greater);
133-
134-
assert(ci1 <=> ci1 == std::strong_ordering::equivalent);
135-
assert(ci1 <=> ci2 == std::strong_ordering::less);
136-
assert(ci2 <=> ci1 == std::strong_ordering::greater);
137-
138-
assert(ri1 <=> ri1 == std::strong_ordering::equivalent);
139-
assert(ri1 <=> ri2 == std::strong_ordering::less);
140-
assert(ri2 <=> ri1 == std::strong_ordering::greater);
141-
142-
assert(cri1 <=> cri1 == std::strong_ordering::equivalent);
143-
assert(cri1 <=> cri2 == std::strong_ordering::less);
144-
assert(cri2 <=> cri1 == std::strong_ordering::greater);
145-
}
117+
static_assert(std::three_way_comparable<I>); // ...of course the wrapped iterators still support <=>.
118+
static_assert(std::three_way_comparable<CI>);
119+
static_assert(std::three_way_comparable<RI>);
120+
static_assert(std::three_way_comparable<CRI>);
121+
static_assert(std::same_as<decltype(I() <=> I()), std::strong_ordering>);
122+
static_assert(std::same_as<decltype(I() <=> CI()), std::strong_ordering>);
123+
static_assert(std::same_as<decltype(CI() <=> CI()), std::strong_ordering>);
124+
static_assert(std::same_as<decltype(RI() <=> RI()), std::strong_ordering>);
125+
static_assert(std::same_as<decltype(RI() <=> CRI()), std::strong_ordering>);
126+
static_assert(std::same_as<decltype(CRI() <=> CRI()), std::strong_ordering>);
127+
128+
assert(i1 <=> i1 == std::strong_ordering::equivalent);
129+
assert(i1 <=> i2 == std::strong_ordering::less);
130+
assert(i2 <=> i1 == std::strong_ordering::greater);
131+
132+
assert(ci1 <=> ci1 == std::strong_ordering::equivalent);
133+
assert(ci1 <=> ci2 == std::strong_ordering::less);
134+
assert(ci2 <=> ci1 == std::strong_ordering::greater);
135+
136+
assert(ri1 <=> ri1 == std::strong_ordering::equivalent);
137+
assert(ri1 <=> ri2 == std::strong_ordering::less);
138+
assert(ri2 <=> ri1 == std::strong_ordering::greater);
139+
140+
assert(cri1 <=> cri1 == std::strong_ordering::equivalent);
141+
assert(cri1 <=> cri2 == std::strong_ordering::less);
142+
assert(cri2 <=> cri1 == std::strong_ordering::greater);
146143
}
147144

148145
int main(int, char**) {

libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.iterators/iterator_comparison.pass.cpp

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ void test() {
2828
using Key = typename KeyContainer::value_type;
2929
using Value = typename ValueContainer::value_type;
3030
using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
31-
using KI = typename KeyContainer::iterator;
3231
using I = M::iterator;
3332
using CI = M::const_iterator;
3433
using RI = M::reverse_iterator;
@@ -115,34 +114,32 @@ void test() {
115114
assert(cri2 >= cri2);
116115
assert(!(cri1 >= cri2));
117116

118-
if constexpr (std::three_way_comparable<KI>) {
119-
static_assert(std::three_way_comparable<I>); // ...of course the wrapped iterators still support <=>.
120-
static_assert(std::three_way_comparable<CI>);
121-
static_assert(std::three_way_comparable<RI>);
122-
static_assert(std::three_way_comparable<CRI>);
123-
static_assert(std::same_as<decltype(I() <=> I()), std::strong_ordering>);
124-
static_assert(std::same_as<decltype(I() <=> CI()), std::strong_ordering>);
125-
static_assert(std::same_as<decltype(CI() <=> CI()), std::strong_ordering>);
126-
static_assert(std::same_as<decltype(RI() <=> RI()), std::strong_ordering>);
127-
static_assert(std::same_as<decltype(RI() <=> CRI()), std::strong_ordering>);
128-
static_assert(std::same_as<decltype(CRI() <=> CRI()), std::strong_ordering>);
129-
130-
assert(i1 <=> i1 == std::strong_ordering::equivalent);
131-
assert(i1 <=> i2 == std::strong_ordering::less);
132-
assert(i2 <=> i1 == std::strong_ordering::greater);
133-
134-
assert(ci1 <=> ci1 == std::strong_ordering::equivalent);
135-
assert(ci1 <=> ci2 == std::strong_ordering::less);
136-
assert(ci2 <=> ci1 == std::strong_ordering::greater);
137-
138-
assert(ri1 <=> ri1 == std::strong_ordering::equivalent);
139-
assert(ri1 <=> ri2 == std::strong_ordering::less);
140-
assert(ri2 <=> ri1 == std::strong_ordering::greater);
141-
142-
assert(cri1 <=> cri1 == std::strong_ordering::equivalent);
143-
assert(cri1 <=> cri2 == std::strong_ordering::less);
144-
assert(cri2 <=> cri1 == std::strong_ordering::greater);
145-
}
117+
static_assert(std::three_way_comparable<I>); // ...of course the wrapped iterators still support <=>.
118+
static_assert(std::three_way_comparable<CI>);
119+
static_assert(std::three_way_comparable<RI>);
120+
static_assert(std::three_way_comparable<CRI>);
121+
static_assert(std::same_as<decltype(I() <=> I()), std::strong_ordering>);
122+
static_assert(std::same_as<decltype(I() <=> CI()), std::strong_ordering>);
123+
static_assert(std::same_as<decltype(CI() <=> CI()), std::strong_ordering>);
124+
static_assert(std::same_as<decltype(RI() <=> RI()), std::strong_ordering>);
125+
static_assert(std::same_as<decltype(RI() <=> CRI()), std::strong_ordering>);
126+
static_assert(std::same_as<decltype(CRI() <=> CRI()), std::strong_ordering>);
127+
128+
assert(i1 <=> i1 == std::strong_ordering::equivalent);
129+
assert(i1 <=> i2 == std::strong_ordering::less);
130+
assert(i2 <=> i1 == std::strong_ordering::greater);
131+
132+
assert(ci1 <=> ci1 == std::strong_ordering::equivalent);
133+
assert(ci1 <=> ci2 == std::strong_ordering::less);
134+
assert(ci2 <=> ci1 == std::strong_ordering::greater);
135+
136+
assert(ri1 <=> ri1 == std::strong_ordering::equivalent);
137+
assert(ri1 <=> ri2 == std::strong_ordering::less);
138+
assert(ri2 <=> ri1 == std::strong_ordering::greater);
139+
140+
assert(cri1 <=> cri1 == std::strong_ordering::equivalent);
141+
assert(cri1 <=> cri2 == std::strong_ordering::less);
142+
assert(cri2 <=> cri1 == std::strong_ordering::greater);
146143
}
147144

148145
int main(int, char**) {

libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.iterators/iterator_comparison.pass.cpp

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ template <class KeyContainer>
2727
void test_one() {
2828
using Key = typename KeyContainer::value_type;
2929
using M = std::flat_multiset<Key, std::less<Key>, KeyContainer>;
30-
using KI = typename KeyContainer::iterator;
3130
using I = M::iterator;
3231
using CI = M::const_iterator;
3332
using RI = M::reverse_iterator;
@@ -114,34 +113,32 @@ void test_one() {
114113
assert(cri2 >= cri2);
115114
assert(!(cri1 >= cri2));
116115

117-
if constexpr (std::three_way_comparable<KI>) {
118-
static_assert(std::three_way_comparable<I>); // ...of course the wrapped iterators still support <=>.
119-
static_assert(std::three_way_comparable<CI>);
120-
static_assert(std::three_way_comparable<RI>);
121-
static_assert(std::three_way_comparable<CRI>);
122-
static_assert(std::same_as<decltype(I() <=> I()), std::strong_ordering>);
123-
static_assert(std::same_as<decltype(I() <=> CI()), std::strong_ordering>);
124-
static_assert(std::same_as<decltype(CI() <=> CI()), std::strong_ordering>);
125-
static_assert(std::same_as<decltype(RI() <=> RI()), std::strong_ordering>);
126-
static_assert(std::same_as<decltype(RI() <=> CRI()), std::strong_ordering>);
127-
static_assert(std::same_as<decltype(CRI() <=> CRI()), std::strong_ordering>);
128-
129-
assert(i1 <=> i1 == std::strong_ordering::equivalent);
130-
assert(i1 <=> i2 == std::strong_ordering::less);
131-
assert(i2 <=> i1 == std::strong_ordering::greater);
132-
133-
assert(ci1 <=> ci1 == std::strong_ordering::equivalent);
134-
assert(ci1 <=> ci2 == std::strong_ordering::less);
135-
assert(ci2 <=> ci1 == std::strong_ordering::greater);
136-
137-
assert(ri1 <=> ri1 == std::strong_ordering::equivalent);
138-
assert(ri1 <=> ri2 == std::strong_ordering::less);
139-
assert(ri2 <=> ri1 == std::strong_ordering::greater);
140-
141-
assert(cri1 <=> cri1 == std::strong_ordering::equivalent);
142-
assert(cri1 <=> cri2 == std::strong_ordering::less);
143-
assert(cri2 <=> cri1 == std::strong_ordering::greater);
144-
}
116+
static_assert(std::three_way_comparable<I>); // ...of course the wrapped iterators still support <=>.
117+
static_assert(std::three_way_comparable<CI>);
118+
static_assert(std::three_way_comparable<RI>);
119+
static_assert(std::three_way_comparable<CRI>);
120+
static_assert(std::same_as<decltype(I() <=> I()), std::strong_ordering>);
121+
static_assert(std::same_as<decltype(I() <=> CI()), std::strong_ordering>);
122+
static_assert(std::same_as<decltype(CI() <=> CI()), std::strong_ordering>);
123+
static_assert(std::same_as<decltype(RI() <=> RI()), std::strong_ordering>);
124+
static_assert(std::same_as<decltype(RI() <=> CRI()), std::strong_ordering>);
125+
static_assert(std::same_as<decltype(CRI() <=> CRI()), std::strong_ordering>);
126+
127+
assert(i1 <=> i1 == std::strong_ordering::equivalent);
128+
assert(i1 <=> i2 == std::strong_ordering::less);
129+
assert(i2 <=> i1 == std::strong_ordering::greater);
130+
131+
assert(ci1 <=> ci1 == std::strong_ordering::equivalent);
132+
assert(ci1 <=> ci2 == std::strong_ordering::less);
133+
assert(ci2 <=> ci1 == std::strong_ordering::greater);
134+
135+
assert(ri1 <=> ri1 == std::strong_ordering::equivalent);
136+
assert(ri1 <=> ri2 == std::strong_ordering::less);
137+
assert(ri2 <=> ri1 == std::strong_ordering::greater);
138+
139+
assert(cri1 <=> cri1 == std::strong_ordering::equivalent);
140+
assert(cri1 <=> cri2 == std::strong_ordering::less);
141+
assert(cri2 <=> cri1 == std::strong_ordering::greater);
145142
}
146143

147144
void test() {

libcxx/test/std/containers/container.adaptors/flat.set/flat.set.iterators/iterator_comparison.pass.cpp

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ template <class KeyContainer>
2727
void test_one() {
2828
using Key = typename KeyContainer::value_type;
2929
using M = std::flat_set<Key, std::less<Key>, KeyContainer>;
30-
using KI = typename KeyContainer::iterator;
3130
using I = M::iterator;
3231
using CI = M::const_iterator;
3332
using RI = M::reverse_iterator;
@@ -114,34 +113,32 @@ void test_one() {
114113
assert(cri2 >= cri2);
115114
assert(!(cri1 >= cri2));
116115

117-
if constexpr (std::three_way_comparable<KI>) {
118-
static_assert(std::three_way_comparable<I>); // ...of course the wrapped iterators still support <=>.
119-
static_assert(std::three_way_comparable<CI>);
120-
static_assert(std::three_way_comparable<RI>);
121-
static_assert(std::three_way_comparable<CRI>);
122-
static_assert(std::same_as<decltype(I() <=> I()), std::strong_ordering>);
123-
static_assert(std::same_as<decltype(I() <=> CI()), std::strong_ordering>);
124-
static_assert(std::same_as<decltype(CI() <=> CI()), std::strong_ordering>);
125-
static_assert(std::same_as<decltype(RI() <=> RI()), std::strong_ordering>);
126-
static_assert(std::same_as<decltype(RI() <=> CRI()), std::strong_ordering>);
127-
static_assert(std::same_as<decltype(CRI() <=> CRI()), std::strong_ordering>);
128-
129-
assert(i1 <=> i1 == std::strong_ordering::equivalent);
130-
assert(i1 <=> i2 == std::strong_ordering::less);
131-
assert(i2 <=> i1 == std::strong_ordering::greater);
132-
133-
assert(ci1 <=> ci1 == std::strong_ordering::equivalent);
134-
assert(ci1 <=> ci2 == std::strong_ordering::less);
135-
assert(ci2 <=> ci1 == std::strong_ordering::greater);
136-
137-
assert(ri1 <=> ri1 == std::strong_ordering::equivalent);
138-
assert(ri1 <=> ri2 == std::strong_ordering::less);
139-
assert(ri2 <=> ri1 == std::strong_ordering::greater);
140-
141-
assert(cri1 <=> cri1 == std::strong_ordering::equivalent);
142-
assert(cri1 <=> cri2 == std::strong_ordering::less);
143-
assert(cri2 <=> cri1 == std::strong_ordering::greater);
144-
}
116+
static_assert(std::three_way_comparable<I>); // ...of course the wrapped iterators still support <=>.
117+
static_assert(std::three_way_comparable<CI>);
118+
static_assert(std::three_way_comparable<RI>);
119+
static_assert(std::three_way_comparable<CRI>);
120+
static_assert(std::same_as<decltype(I() <=> I()), std::strong_ordering>);
121+
static_assert(std::same_as<decltype(I() <=> CI()), std::strong_ordering>);
122+
static_assert(std::same_as<decltype(CI() <=> CI()), std::strong_ordering>);
123+
static_assert(std::same_as<decltype(RI() <=> RI()), std::strong_ordering>);
124+
static_assert(std::same_as<decltype(RI() <=> CRI()), std::strong_ordering>);
125+
static_assert(std::same_as<decltype(CRI() <=> CRI()), std::strong_ordering>);
126+
127+
assert(i1 <=> i1 == std::strong_ordering::equivalent);
128+
assert(i1 <=> i2 == std::strong_ordering::less);
129+
assert(i2 <=> i1 == std::strong_ordering::greater);
130+
131+
assert(ci1 <=> ci1 == std::strong_ordering::equivalent);
132+
assert(ci1 <=> ci2 == std::strong_ordering::less);
133+
assert(ci2 <=> ci1 == std::strong_ordering::greater);
134+
135+
assert(ri1 <=> ri1 == std::strong_ordering::equivalent);
136+
assert(ri1 <=> ri2 == std::strong_ordering::less);
137+
assert(ri2 <=> ri1 == std::strong_ordering::greater);
138+
139+
assert(cri1 <=> cri1 == std::strong_ordering::equivalent);
140+
assert(cri1 <=> cri2 == std::strong_ordering::less);
141+
assert(cri2 <=> cri1 == std::strong_ordering::greater);
145142
}
146143

147144
void test() {

libcxx/test/support/MinSequenceContainer.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
#include "test_iterators.h"
1616

17-
template <class T, class Iterator = random_access_iterator<T*>, class ConstIterator = random_access_iterator<const T*>>
17+
template <class T,
18+
class Iterator = three_way_random_access_iterator<T*>,
19+
class ConstIterator = three_way_random_access_iterator<const T*>>
1820
struct MinSequenceContainer {
1921
using value_type = T;
2022
using difference_type = int;

0 commit comments

Comments
 (0)