Skip to content

Commit 2aac2cf

Browse files
committed
ctor
1 parent 355a23a commit 2aac2cf

18 files changed

+707
-421
lines changed

libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.cons/alloc.pass.cpp

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// explicit flat_multiset(const Allocator& a);
1515

1616
#include <cassert>
17+
#include <deque>
1718
#include <flat_set>
1819
#include <functional>
1920
#include <vector>
@@ -22,7 +23,19 @@
2223
#include "test_allocator.h"
2324
#include "../../../test_compare.h"
2425

25-
void test() {
26+
template <template <class...> class KeyContainer>
27+
constexpr void test() {
28+
{
29+
using A = test_allocator<short>;
30+
using M = std::flat_multiset<int, std::less<int>, KeyContainer<int, test_allocator<int>>>;
31+
M m(A(0, 5));
32+
assert(m.empty());
33+
assert(m.begin() == m.end());
34+
assert(std::move(m).extract().get_allocator().get_id() == 5);
35+
}
36+
}
37+
38+
constexpr bool test() {
2639
{
2740
// The constructors in this subclause shall not participate in overload
2841
// resolution unless uses_allocator_v<container_type, Alloc> is true
@@ -46,18 +59,21 @@ void test() {
4659
static_assert(std::is_constructible_v<M, test_allocator<int>>);
4760
static_assert(!std::is_convertible_v<test_allocator<int>, M>);
4861
}
49-
{
50-
using A = test_allocator<short>;
51-
using M = std::flat_multiset<int, std::less<int>, std::vector<int, test_allocator<int>>>;
52-
M m(A(0, 5));
53-
assert(m.empty());
54-
assert(m.begin() == m.end());
55-
assert(std::move(m).extract().get_allocator().get_id() == 5);
56-
}
62+
63+
test<std::vector>();
64+
#ifndef __cpp_lib_constexpr_deque
65+
if (!TEST_IS_CONSTANT_EVALUATED)
66+
#endif
67+
test<std::deque>();
68+
69+
return true;
5770
}
5871

5972
int main(int, char**) {
6073
test();
74+
#if TEST_STD_VER >= 26
75+
static_assert(test());
76+
#endif
6177

6278
return 0;
6379
}

libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.cons/assign_initializer_list.pass.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "test_allocator.h"
2727

2828
template <class KeyContainer>
29-
void test() {
29+
constexpr void test() {
3030
using Key = typename KeyContainer::value_type;
3131
using M = std::flat_multiset<Key, std::less<Key>, KeyContainer>;
3232
{
@@ -53,16 +53,24 @@ void test() {
5353
}
5454
}
5555

56-
void test() {
56+
constexpr bool test() {
5757
test<std::vector<int>>();
5858
test<std::vector<double>>();
59-
test<std::deque<int>>();
59+
#ifndef __cpp_lib_constexpr_deque
60+
if (!TEST_IS_CONSTANT_EVALUATED)
61+
#endif
62+
test<std::deque<int>>();
6063
test<MinSequenceContainer<int>>();
6164
test<std::vector<int, min_allocator<int>>>();
65+
66+
return true;
6267
}
6368

6469
int main(int, char**) {
6570
test();
71+
#if TEST_STD_VER >= 26
72+
static_assert(test());
73+
#endif
6674

6775
return 0;
6876
}

libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.cons/compare.pass.cpp

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,66 +20,96 @@
2020
#include <type_traits>
2121
#include <vector>
2222

23+
#include "MinSequenceContainer.h"
24+
#include "min_allocator.h"
2325
#include "test_macros.h"
2426
#include "../../../test_compare.h"
2527
#include "test_allocator.h"
2628

27-
void test() {
29+
template <class KeyContainer>
30+
constexpr void test_compare() {
31+
using Key = typename KeyContainer::value_type;
2832
{
29-
// The constructors in this subclause shall not participate in overload
30-
// resolution unless uses_allocator_v<container_type, Alloc> is true
33+
// The one-argument ctor is explicit.
34+
using C = test_less<Key>;
35+
static_assert(std::is_constructible_v<std::flat_multiset<Key, C>, C>);
36+
static_assert(!std::is_convertible_v<C, std::flat_multiset<Key, C>>);
3137

32-
using C = test_less<int>;
33-
using A1 = test_allocator<int>;
34-
using A2 = other_allocator<int>;
35-
using V1 = std::vector<int, A1>;
36-
using V2 = std::vector<int, A2>;
37-
using M1 = std::flat_multiset<int, C, V1>;
38-
using M2 = std::flat_multiset<int, C, V2>;
39-
static_assert(std::is_constructible_v<M1, const C&, const A1&>);
40-
static_assert(std::is_constructible_v<M2, const C&, const A2&>);
41-
static_assert(!std::is_constructible_v<M1, const C&, const A2&>);
42-
static_assert(!std::is_constructible_v<M2, const C&, const A1&>);
38+
static_assert(std::is_constructible_v<std::flat_multiset<Key>, std::less<Key>>);
39+
static_assert(!std::is_convertible_v<std::less<Key>, std::flat_multiset<Key>>);
4340
}
4441
{
45-
using C = test_less<int>;
46-
auto m = std::flat_multiset<int, C>(C(3));
42+
using C = test_less<Key>;
43+
auto m = std::flat_multiset<Key, C>(C(3));
4744
assert(m.empty());
4845
assert(m.begin() == m.end());
4946
assert(m.key_comp() == C(3));
5047
}
51-
{
52-
// The one-argument ctor is explicit.
53-
using C = test_less<int>;
54-
static_assert(std::is_constructible_v<std::flat_multiset<int, C>, C>);
55-
static_assert(!std::is_convertible_v<C, std::flat_multiset<int, C>>);
48+
}
5649

57-
static_assert(std::is_constructible_v<std::flat_multiset<int>, std::less<int>>);
58-
static_assert(!std::is_convertible_v<std::less<int>, std::flat_multiset<int>>);
59-
}
50+
template <template <class...> class KeyContainer>
51+
constexpr void test_compare_alloc() {
6052
{
6153
using C = test_less<int>;
6254
using A1 = test_allocator<int>;
63-
auto m = std::flat_multiset<int, C, std::vector<int, A1>>(C(4), A1(5));
55+
auto m = std::flat_multiset<int, C, KeyContainer<int, A1>>(C(4), A1(5));
6456
assert(m.empty());
6557
assert(m.begin() == m.end());
6658
assert(m.key_comp() == C(4));
6759
assert(std::move(m).extract().get_allocator() == A1(5));
6860
}
6961
{
7062
// explicit(false)
71-
using C = test_less<int>;
72-
using A1 = test_allocator<int>;
73-
std::flat_multiset<int, C, std::deque<int, A1>> m = {C(4), A1(5)};
63+
using C = test_less<int>;
64+
using A1 = test_allocator<int>;
65+
std::flat_multiset<int, C, KeyContainer<int, A1>> m = {C(4), A1(5)};
7466
assert(m.empty());
7567
assert(m.begin() == m.end());
7668
assert(m.key_comp() == C(4));
7769
assert(std::move(m).extract().get_allocator() == A1(5));
7870
}
7971
}
8072

73+
constexpr bool test() {
74+
{
75+
// The constructors in this subclause shall not participate in overload
76+
// resolution unless uses_allocator_v<container_type, Alloc> is true
77+
78+
using C = test_less<int>;
79+
using A1 = test_allocator<int>;
80+
using A2 = other_allocator<int>;
81+
using V1 = std::vector<int, A1>;
82+
using V2 = std::vector<int, A2>;
83+
using M1 = std::flat_multiset<int, C, V1>;
84+
using M2 = std::flat_multiset<int, C, V2>;
85+
static_assert(std::is_constructible_v<M1, const C&, const A1&>);
86+
static_assert(std::is_constructible_v<M2, const C&, const A2&>);
87+
static_assert(!std::is_constructible_v<M1, const C&, const A2&>);
88+
static_assert(!std::is_constructible_v<M2, const C&, const A1&>);
89+
}
90+
91+
test_compare<std::vector<int>>();
92+
test_compare<MinSequenceContainer<int>>();
93+
test_compare<std::vector<int, min_allocator<int>>>();
94+
95+
test_compare_alloc<std::vector>();
96+
97+
#ifndef __cpp_lib_constexpr_deque
98+
if (!TEST_IS_CONSTANT_EVALUATED)
99+
#endif
100+
{
101+
test_compare<std::deque<int>>();
102+
test_compare_alloc<std::deque>();
103+
}
104+
105+
return true;
106+
}
107+
81108
int main(int, char**) {
82109
test();
110+
#if TEST_STD_VER >= 26
111+
static_assert(test());
112+
#endif
83113

84114
return 0;
85115
}

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

Lines changed: 63 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -35,39 +35,19 @@ void conversion_test(T);
3535
template <class T, class... Args>
3636
concept ImplicitlyConstructible = requires(Args&&... args) { conversion_test<T>({std::forward<Args>(args)...}); };
3737

38-
void test() {
39-
{
40-
// The constructors in this subclause shall not participate in overload
41-
// resolution unless uses_allocator_v<container_type, Alloc> is true
42-
43-
using C = test_less<int>;
44-
using A1 = test_allocator<int>;
45-
using A2 = other_allocator<int>;
46-
using V1 = std::vector<int, A1>;
47-
using V2 = std::vector<int, A2>;
48-
using M1 = std::flat_multiset<int, C, V1>;
49-
using M2 = std::flat_multiset<int, C, V2>;
50-
static_assert(std::is_constructible_v<M1, const V1&, const A1&>);
51-
static_assert(std::is_constructible_v<M2, const V2&, const A2&>);
52-
static_assert(!std::is_constructible_v<M1, const V1&, const A2&>);
53-
static_assert(!std::is_constructible_v<M2, const V2&, const A1&>);
54-
55-
static_assert(std::is_constructible_v<M1, const V1&, const C&, const A1&>);
56-
static_assert(std::is_constructible_v<M2, const V2&, const C&, const A2&>);
57-
static_assert(!std::is_constructible_v<M1, const V1&, const C&, const A2&>);
58-
static_assert(!std::is_constructible_v<M2, const V2&, const C&, const A1&>);
59-
}
38+
template <template <class...> class KeyContainer>
39+
constexpr void test() {
6040
{
6141
// flat_multiset(container_type)
62-
using M = std::flat_multiset<int>;
63-
std::vector<int> ks = {1, 1, 1, 2, 2, 3, 2, 3, 3};
64-
auto m = M(ks);
65-
int expected[] = {1, 1, 1, 2, 2, 2, 3, 3, 3};
42+
using M = std::flat_multiset<int, std::less<int>, KeyContainer<int>>;
43+
KeyContainer<int> ks = {1, 1, 1, 2, 2, 3, 2, 3, 3};
44+
auto m = M(ks);
45+
int expected[] = {1, 1, 1, 2, 2, 2, 3, 3, 3};
6646
assert(std::ranges::equal(m, expected));
6747

6848
// explicit(false)
69-
static_assert(std::is_constructible_v<M, const std::vector<int>&>);
70-
static_assert(!ImplicitlyConstructible<M, const std::vector<int>&>);
49+
static_assert(std::is_constructible_v<M, const KeyContainer<int>&>);
50+
static_assert(!ImplicitlyConstructible<M, const KeyContainer<int>&>);
7151

7252
m = M(std::move(ks));
7353
assert(ks.empty()); // it was moved-from
@@ -77,7 +57,7 @@ void test() {
7757
// flat_multiset(container_type)
7858
// move-only
7959
int expected[] = {3, 3, 2, 1};
80-
using Ks = std::deque<MoveOnly, min_allocator<MoveOnly>>;
60+
using Ks = KeyContainer<MoveOnly, min_allocator<MoveOnly>>;
8161
using M = std::flat_multiset<MoveOnly, std::greater<MoveOnly>, Ks>;
8262
Ks ks;
8363
ks.push_back(1);
@@ -92,8 +72,8 @@ void test() {
9272
// flat_multiset(container_type)
9373
// container's allocators are used
9474
using A = test_allocator<int>;
95-
using M = std::flat_multiset<int, std::less<int>, std::deque<int, A>>;
96-
auto ks = std::deque<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(5));
75+
using M = std::flat_multiset<int, std::less<int>, KeyContainer<int, A>>;
76+
auto ks = KeyContainer<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(5));
9777
auto m = M(std::move(ks));
9878
assert(ks.empty()); // it was moved-from
9979
assert((m == M{1, 1, 1, 2, 2, 2, 3, 3, 3}));
@@ -102,30 +82,30 @@ void test() {
10282
}
10383
{
10484
// flat_multiset(container_type, key_compare)
105-
using C = test_less<int>;
106-
using M = std::flat_multiset<int, C>;
107-
std::vector<int> ks = {1, 1, 1, 2, 2, 3, 2, 3, 3};
108-
auto m = M(ks, C(4));
85+
using C = test_less<int>;
86+
using M = std::flat_multiset<int, C, KeyContainer<int>>;
87+
KeyContainer<int> ks = {1, 1, 1, 2, 2, 3, 2, 3, 3};
88+
auto m = M(ks, C(4));
10989
assert(std::ranges::equal(m, std::vector<int>{1, 1, 1, 2, 2, 2, 3, 3, 3}));
11090
assert(m.key_comp() == C(4));
11191

11292
// explicit
113-
static_assert(std::is_constructible_v<M, const std::vector<int>&, const C&>);
114-
static_assert(!ImplicitlyConstructible<M, const std::vector<int>&, const C&>);
93+
static_assert(std::is_constructible_v<M, const KeyContainer<int>&, const C&>);
94+
static_assert(!ImplicitlyConstructible<M, const KeyContainer<int>&, const C&>);
11595
}
11696
{
11797
// flat_multiset(container_type , const Allocator&)
11898
using A = test_allocator<int>;
119-
using M = std::flat_multiset<int, std::less<int>, std::deque<int, A>>;
120-
auto ks = std::deque<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(5));
99+
using M = std::flat_multiset<int, std::less<int>, KeyContainer<int, A>>;
100+
auto ks = KeyContainer<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(5));
121101
auto m = M(ks, A(4)); // replaces the allocators
122102
assert(!ks.empty()); // it was an lvalue above
123103
assert((m == M{1, 1, 1, 2, 2, 2, 3, 3, 3}));
124104
auto keys = M(m).extract();
125105
assert(keys.get_allocator() == A(4));
126106

127107
// explicit(false)
128-
static_assert(ImplicitlyConstructible<M, const std::deque<int, A>&, const A&>);
108+
static_assert(ImplicitlyConstructible<M, const KeyContainer<int, A>&, const A&>);
129109
M m2 = {ks, A(4)}; // implicit ctor
130110
assert(!ks.empty()); // it was an lvalue above
131111
assert(m2 == m);
@@ -134,19 +114,19 @@ void test() {
134114
}
135115
{
136116
// flat_multiset(container_type , const Allocator&)
137-
using C = test_less<int>;
138-
using A = test_allocator<int>;
139-
using M = std::flat_multiset<int, C, std::vector<int, A>>;
140-
std::vector<int, A> ks = {1, 1, 1, 2, 2, 3, 2, 3, 3};
141-
auto m = M(ks, C(4), A(5));
142-
assert(std::ranges::equal(m, std::vector<int, A>{1, 1, 1, 2, 2, 2, 3, 3, 3}));
117+
using C = test_less<int>;
118+
using A = test_allocator<int>;
119+
using M = std::flat_multiset<int, C, KeyContainer<int, A>>;
120+
KeyContainer<int, A> ks = {1, 1, 1, 2, 2, 3, 2, 3, 3};
121+
auto m = M(ks, C(4), A(5));
122+
assert(std::ranges::equal(m, KeyContainer<int, A>{1, 1, 1, 2, 2, 2, 3, 3, 3}));
143123
assert(m.key_comp() == C(4));
144124
auto m_copy = m;
145125
auto keys = std::move(m_copy).extract();
146126
assert(keys.get_allocator() == A(5));
147127

148128
// explicit(false)
149-
static_assert(ImplicitlyConstructible<M, const std::vector<int, A>&, const A&>);
129+
static_assert(ImplicitlyConstructible<M, const KeyContainer<int, A>&, const A&>);
150130
M m2 = {ks, C(4), A(5)};
151131
assert(m2 == m);
152132
assert(m2.key_comp() == C(4));
@@ -155,8 +135,44 @@ void test() {
155135
}
156136
}
157137

138+
constexpr bool test() {
139+
{
140+
// The constructors in this subclause shall not participate in overload
141+
// resolution unless uses_allocator_v<container_type, Alloc> is true
142+
143+
using C = test_less<int>;
144+
using A1 = test_allocator<int>;
145+
using A2 = other_allocator<int>;
146+
using V1 = std::vector<int, A1>;
147+
using V2 = std::vector<int, A2>;
148+
using M1 = std::flat_multiset<int, C, V1>;
149+
using M2 = std::flat_multiset<int, C, V2>;
150+
static_assert(std::is_constructible_v<M1, const V1&, const A1&>);
151+
static_assert(std::is_constructible_v<M2, const V2&, const A2&>);
152+
static_assert(!std::is_constructible_v<M1, const V1&, const A2&>);
153+
static_assert(!std::is_constructible_v<M2, const V2&, const A1&>);
154+
155+
static_assert(std::is_constructible_v<M1, const V1&, const C&, const A1&>);
156+
static_assert(std::is_constructible_v<M2, const V2&, const C&, const A2&>);
157+
static_assert(!std::is_constructible_v<M1, const V1&, const C&, const A2&>);
158+
static_assert(!std::is_constructible_v<M2, const V2&, const C&, const A1&>);
159+
}
160+
161+
test<std::vector>();
162+
163+
#ifndef __cpp_lib_constexpr_deque
164+
if (!TEST_IS_CONSTANT_EVALUATED)
165+
#endif
166+
test<std::deque>();
167+
168+
return true;
169+
}
170+
158171
int main(int, char**) {
159172
test();
173+
#if TEST_STD_VER >= 26
174+
static_assert(test());
175+
#endif
160176

161177
return 0;
162178
}

0 commit comments

Comments
 (0)