Skip to content

Commit 241ea9e

Browse files
committed
[libc++] constexpr flat_multiset
1 parent db2a5a9 commit 241ea9e

File tree

9 files changed

+234
-162
lines changed

9 files changed

+234
-162
lines changed

libcxx/include/__flat_set/flat_multiset.h

Lines changed: 102 additions & 102 deletions
Large diffs are not rendered by default.

libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.capacity/empty.pass.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "min_allocator.h"
2525

2626
template <class KeyContainer>
27-
void test_one() {
27+
constexpr void test_one() {
2828
using Key = typename KeyContainer::value_type;
2929
using M = std::flat_multiset<Key, std::less<int>, KeyContainer>;
3030
M m;
@@ -38,15 +38,23 @@ void test_one() {
3838
assert(m.empty());
3939
}
4040

41-
void test() {
41+
constexpr bool test() {
4242
test_one<std::vector<int>>();
43-
test_one<std::deque<int>>();
43+
#ifndef __cpp_lib_constexpr_deque
44+
if (!TEST_IS_CONSTANT_EVALUATED)
45+
#endif
46+
test_one<std::deque<int>>();
4447
test_one<MinSequenceContainer<int>>();
4548
test_one<std::vector<int, min_allocator<int>>>();
49+
50+
return true;
4651
}
4752

4853
int main(int, char**) {
4954
test();
55+
#if TEST_STD_VER >= 26
56+
static_assert(test());
57+
#endif
5058

5159
return 0;
5260
}

libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.capacity/max_size.pass.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "test_allocator.h"
2525
#include "test_macros.h"
2626

27-
void test() {
27+
constexpr bool test() {
2828
{
2929
using A1 = limited_allocator<int, 10>;
3030
using C = std::flat_multiset<int, std::less<int>, std::vector<int, A1>>;
@@ -59,10 +59,15 @@ void test() {
5959
assert(c.max_size() <= max_dist);
6060
assert(c.max_size() <= alloc_max_size(std::allocator<char>()));
6161
}
62+
63+
return true;
6264
}
6365

6466
int main(int, char**) {
6567
test();
68+
#if TEST_STD_VER >= 26
69+
static_assert(test());
70+
#endif
6671

6772
return 0;
6873
}

libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.capacity/size.pass.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
//===----------------------------------------------------------------------===//
88

99
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10+
// ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-steps): -fconstexpr-steps=200000000
11+
// ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-ops-limit): -fconstexpr-ops-limit=800000000
1012

1113
// <flat_set>
1214

@@ -23,7 +25,7 @@
2325
#include "min_allocator.h"
2426

2527
template <class KeyContainer>
26-
void test_one() {
28+
constexpr void test_one() {
2729
using M = std::flat_multiset<int, std::less<int>, KeyContainer>;
2830
using S = typename M::size_type;
2931
{
@@ -46,7 +48,7 @@ void test_one() {
4648
}
4749
{
4850
M m;
49-
S s = 500000;
51+
S s = 5000;
5052
for (std::size_t i = 0u; i < s; ++i) {
5153
m.emplace(i);
5254
m.emplace(i);
@@ -57,15 +59,23 @@ void test_one() {
5759
}
5860
}
5961

60-
void test() {
62+
constexpr bool test() {
6163
test_one<std::vector<int>>();
62-
test_one<std::deque<int>>();
64+
#ifndef __cpp_lib_constexpr_deque
65+
if (!TEST_IS_CONSTANT_EVALUATED)
66+
#endif
67+
test_one<std::deque<int>>();
6368
test_one<MinSequenceContainer<int>>();
6469
test_one<std::vector<int, min_allocator<int>>>();
70+
71+
return true;
6572
}
6673

6774
int main(int, char**) {
6875
test();
76+
#if TEST_STD_VER >= 26
77+
static_assert(test());
78+
#endif
6979

7080
return 0;
7181
}

libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.erasure/erase_if.pass.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ static_assert(HasStdErase<std::vector<int>>);
3232
static_assert(!HasStdErase<std::flat_multiset<int>>);
3333

3434
template <class M>
35-
M make(std::initializer_list<int> vals) {
35+
constexpr M make(std::initializer_list<int> vals) {
3636
M ret;
3737
for (int v : vals)
3838
ret.emplace(v);
3939
return ret;
4040
}
4141

4242
template <class M, class Pred>
43-
void test0(
43+
constexpr void test0(
4444
std::initializer_list<int> vals, Pred p, std::initializer_list<int> expected, std::size_t expected_erased_count) {
4545
M s = make<M>(vals);
4646
ASSERT_SAME_TYPE(typename M::size_type, decltype(std::erase_if(s, p)));
@@ -50,11 +50,11 @@ void test0(
5050

5151
struct NotBool {
5252
bool b;
53-
explicit operator bool() const { return b; }
53+
explicit constexpr operator bool() const { return b; }
5454
};
5555

5656
template <class S>
57-
void test_one() {
57+
constexpr void test_one() {
5858
// Test all the plausible signatures for this predicate.
5959
auto is1 = [](typename S::const_reference v) { return v == 1; };
6060
auto is2 = [](typename S::value_type v) { return v == 2; };
@@ -96,18 +96,28 @@ void test_one() {
9696
test0<S>({1, 1, 2, 2, 3}, nonBoolIs1, {2, 2, 3}, 2);
9797
}
9898

99-
void test() {
99+
constexpr bool test() {
100100
test_one<std::flat_multiset<int>>();
101101
test_one<std::flat_multiset<int, std::less<int>, std::vector<int, min_allocator<int>>>>();
102102
test_one<std::flat_multiset<int, std::greater<int>, std::vector<int, test_allocator<int>>>>();
103-
test_one<std::flat_multiset<int, std::less<int>, std::deque<int, min_allocator<int>>>>();
104-
test_one<std::flat_multiset<int, std::greater<int>, std::deque<int, test_allocator<int>>>>();
103+
#ifndef __cpp_lib_constexpr_deque
104+
if (!TEST_IS_CONSTANT_EVALUATED)
105+
#endif
106+
{
107+
test_one<std::flat_multiset<int, std::less<int>, std::deque<int, min_allocator<int>>>>();
108+
test_one<std::flat_multiset<int, std::greater<int>, std::deque<int, test_allocator<int>>>>();
109+
}
105110
test_one<std::flat_multiset<long>>();
106111
test_one<std::flat_multiset<double>>();
112+
113+
return true;
107114
}
108115

109116
int main(int, char**) {
110117
test();
118+
#if TEST_STD_VER >= 26
119+
static_assert(test());
120+
#endif
111121

112122
return 0;
113123
}

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "min_allocator.h"
3131

3232
template <class KeyContainer>
33-
void test_one() {
33+
constexpr void test_one() {
3434
using Key = typename KeyContainer::value_type;
3535
using M = std::flat_multiset<Key, std::less<Key>, KeyContainer>;
3636

@@ -68,9 +68,12 @@ void test_one() {
6868
assert(i == m.begin());
6969
}
7070

71-
void test() {
71+
constexpr bool test() {
7272
test_one<std::vector<int>>();
73-
test_one<std::deque<int>>();
73+
#ifndef __cpp_lib_constexpr_deque
74+
if (!TEST_IS_CONSTANT_EVALUATED)
75+
#endif
76+
test_one<std::deque<int>>();
7477
test_one<MinSequenceContainer<int>>();
7578
test_one<std::vector<int, min_allocator<int>>>();
7679

@@ -89,10 +92,15 @@ void test() {
8992
assert(!(ii1 != cii));
9093
assert(!(cii != ii1));
9194
}
95+
96+
return true;
9297
}
9398

9499
int main(int, char**) {
95100
test();
101+
#if TEST_STD_VER >= 26
102+
static_assert(test());
103+
#endif
96104

97105
return 0;
98106
}

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "min_allocator.h"
2525

2626
template <class KeyContainer>
27-
void test_one() {
27+
constexpr void test_one() {
2828
using Key = typename KeyContainer::value_type;
2929
using M = std::flat_multiset<Key, std::less<Key>, KeyContainer>;
3030
using I = M::iterator;
@@ -141,15 +141,23 @@ void test_one() {
141141
assert(cri2 <=> cri1 == std::strong_ordering::greater);
142142
}
143143

144-
void test() {
144+
constexpr bool test() {
145145
test_one<std::vector<int>>();
146-
test_one<std::deque<int>>();
146+
#ifndef __cpp_lib_constexpr_deque
147+
if (!TEST_IS_CONSTANT_EVALUATED)
148+
#endif
149+
test_one<std::deque<int>>();
147150
test_one<MinSequenceContainer<int>>();
148151
test_one<std::vector<int, min_allocator<int>>>();
152+
153+
return true;
149154
}
150155

151156
int main(int, char**) {
152157
test();
158+
#if TEST_STD_VER >= 26
159+
static_assert(test());
160+
#endif
153161

154162
return 0;
155163
}

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

Lines changed: 55 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,46 +25,59 @@
2525

2626
#include <iterator>
2727

28+
#include "MinSequenceContainer.h"
2829
#include "test_macros.h"
30+
#include "min_allocator.h"
2931

30-
void test() {
31-
{
32-
using M = std::flat_multiset<int, std::less<int>, std::deque<int>>;
33-
M m = {1, 1, 2, 2, 3, 4};
34-
int expected[] = {1, 1, 2, 2, 3, 4};
35-
const M& cm = m;
36-
ASSERT_SAME_TYPE(decltype(m.rbegin()), M::reverse_iterator);
37-
ASSERT_SAME_TYPE(decltype(m.crbegin()), M::const_reverse_iterator);
38-
ASSERT_SAME_TYPE(decltype(cm.rbegin()), M::const_reverse_iterator);
39-
ASSERT_SAME_TYPE(decltype(m.rend()), M::reverse_iterator);
40-
ASSERT_SAME_TYPE(decltype(m.crend()), M::const_reverse_iterator);
41-
ASSERT_SAME_TYPE(decltype(cm.rend()), M::const_reverse_iterator);
42-
static_assert(noexcept(m.rbegin()));
43-
static_assert(noexcept(cm.rbegin()));
44-
static_assert(noexcept(m.crbegin()));
45-
static_assert(noexcept(m.rend()));
46-
static_assert(noexcept(cm.rend()));
47-
static_assert(noexcept(m.crend()));
48-
assert(m.size() == 6);
49-
assert(std::distance(m.rbegin(), m.rend()) == 6);
50-
assert(std::distance(cm.rbegin(), cm.rend()) == 6);
51-
assert(std::distance(m.crbegin(), m.crend()) == 6);
52-
assert(std::distance(cm.crbegin(), cm.crend()) == 6);
53-
M::reverse_iterator i; // default-construct
54-
ASSERT_SAME_TYPE(decltype(*i), const int&);
55-
i = m.rbegin(); // move-assignment
56-
M::const_reverse_iterator k = i; // converting constructor
57-
assert(i == k); // comparison
58-
for (int j = 5; j >= 0; --j, ++i) { // pre-increment
59-
assert(*i == expected[j]);
60-
}
61-
assert(i == m.rend());
62-
for (int j = 0; j <= 5; ++j) {
63-
--i; // pre-decrement
64-
assert(*i == expected[j]);
65-
}
66-
assert(i == m.rbegin());
32+
template <class KeyContainer>
33+
constexpr void test_one() {
34+
using Key = typename KeyContainer::value_type;
35+
using M = std::flat_multiset<Key, std::less<Key>, KeyContainer>;
36+
M m = {1, 1, 2, 2, 3, 4};
37+
int expected[] = {1, 1, 2, 2, 3, 4};
38+
const M& cm = m;
39+
ASSERT_SAME_TYPE(decltype(m.rbegin()), typename M::reverse_iterator);
40+
ASSERT_SAME_TYPE(decltype(m.crbegin()), typename M::const_reverse_iterator);
41+
ASSERT_SAME_TYPE(decltype(cm.rbegin()), typename M::const_reverse_iterator);
42+
ASSERT_SAME_TYPE(decltype(m.rend()), typename M::reverse_iterator);
43+
ASSERT_SAME_TYPE(decltype(m.crend()), typename M::const_reverse_iterator);
44+
ASSERT_SAME_TYPE(decltype(cm.rend()), typename M::const_reverse_iterator);
45+
static_assert(noexcept(m.rbegin()));
46+
static_assert(noexcept(cm.rbegin()));
47+
static_assert(noexcept(m.crbegin()));
48+
static_assert(noexcept(m.rend()));
49+
static_assert(noexcept(cm.rend()));
50+
static_assert(noexcept(m.crend()));
51+
assert(m.size() == 6);
52+
assert(std::distance(m.rbegin(), m.rend()) == 6);
53+
assert(std::distance(cm.rbegin(), cm.rend()) == 6);
54+
assert(std::distance(m.crbegin(), m.crend()) == 6);
55+
assert(std::distance(cm.crbegin(), cm.crend()) == 6);
56+
typename M::reverse_iterator i; // default-construct
57+
ASSERT_SAME_TYPE(decltype(*i), const int&);
58+
i = m.rbegin(); // move-assignment
59+
typename M::const_reverse_iterator k = i; // converting constructor
60+
assert(i == k); // comparison
61+
for (int j = 5; j >= 0; --j, ++i) { // pre-increment
62+
assert(*i == expected[j]);
63+
}
64+
assert(i == m.rend());
65+
for (int j = 0; j <= 5; ++j) {
66+
--i; // pre-decrement
67+
assert(*i == expected[j]);
6768
}
69+
assert(i == m.rbegin());
70+
}
71+
72+
constexpr bool test() {
73+
test_one<std::vector<int>>();
74+
#ifndef __cpp_lib_constexpr_deque
75+
if (!TEST_IS_CONSTANT_EVALUATED)
76+
#endif
77+
test_one<std::deque<int>>();
78+
test_one<MinSequenceContainer<int>>();
79+
test_one<std::vector<int, min_allocator<int>>>();
80+
6881
{
6982
// N3644 testing
7083
using C = std::flat_multiset<int>;
@@ -80,10 +93,15 @@ void test() {
8093
assert(!(ii1 != cii));
8194
assert(!(cii != ii1));
8295
}
96+
97+
return true;
8398
}
8499

85100
int main(int, char**) {
86101
test();
102+
#if TEST_STD_VER >= 26
103+
static_assert(test());
104+
#endif
87105

88106
return 0;
89107
}

libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.observers/comp.pass.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#include "test_macros.h"
2323

24-
void test() {
24+
constexpr bool test() {
2525
{
2626
using M = std::flat_multiset<int>;
2727
using Comp = std::less<int>; // the default
@@ -36,7 +36,7 @@ void test() {
3636
assert(vc(1, 2));
3737
assert(!vc(2, 1));
3838
}
39-
{
39+
if (!TEST_IS_CONSTANT_EVALUATED) {
4040
using Comp = std::function<bool(int, int)>;
4141
using M = std::flat_multiset<int, Comp>;
4242
Comp comp = std::greater<int>();
@@ -67,10 +67,15 @@ void test() {
6767
assert(vc(1, 2));
6868
assert(!vc(2, 1));
6969
}
70+
71+
return true;
7072
}
7173

7274
int main(int, char**) {
7375
test();
76+
#if TEST_STD_VER >= 26
77+
static_assert(test());
78+
#endif
7479

7580
return 0;
7681
}

0 commit comments

Comments
 (0)