Debian Codegraph @

libstdc++-v3/testsuite/23_containers/unordered_multiset/cons/deduction.cc

raw
1 // { dg-do compile { target c++17 } }
2
3 #include <unordered_set>
4 #include <testsuite_allocator.h>
5
6 using __gnu_test::SimpleAllocator;
7
8 static_assert(std::is_same_v<
9 decltype(std::unordered_multiset{1, 2, 3}),
10 std::unordered_multiset<int>>);
11
12 static_assert(std::is_same_v<
13 decltype(std::unordered_multiset{{1, 2, 3},
14 0, std::hash<int>{}, std::equal_to<int>{}}),
15 std::unordered_multiset<int>>);
16
17 static_assert(std::is_same_v<
18 decltype(std::unordered_multiset{{1, 2, 3},
19 0, std::hash<int>{}, std::allocator<int>{}}),
20 std::unordered_multiset<int>>);
21
22 static_assert(std::is_same_v<
23 decltype(std::unordered_multiset{{1, 2, 3},
24 {}}),
25 std::unordered_multiset<int>>);
26
27 static_assert(std::is_same_v<
28 decltype(std::unordered_multiset{{1, 2, 3},
29 1}),
30 std::unordered_multiset<int>>);
31
32 static_assert(std::is_same_v<
33 decltype(std::unordered_multiset{{1, 2, 3},
34 1, std::allocator<int>{}}),
35 std::unordered_multiset<int>>);
36
37 static_assert(std::is_same_v<
38 decltype(std::unordered_multiset{{1, 2, 3},
39 1, SimpleAllocator<int>{}}),
40 std::unordered_multiset<int, std::hash<int>,
41 std::equal_to<int>,
42 SimpleAllocator<int>>>);
43
44 static_assert(std::is_same_v<
45 decltype(std::unordered_multiset{{1, 2, 3},
46 1, std::hash<int>{}, std::allocator<int>{}}),
47 std::unordered_multiset<int>>);
48
49 static_assert(std::is_same_v<
50 decltype(std::unordered_multiset{{1, 2, 3},
51 1, std::hash<int>{}, SimpleAllocator<int>{}}),
52 std::unordered_multiset<int, std::hash<int>,
53 std::equal_to<int>,
54 SimpleAllocator<int>>>);
55
56 static_assert(std::is_same_v<
57 decltype(std::unordered_multiset{{1, 2, 3},
58 {}, {}, {}, std::allocator<int>{}}),
59 std::unordered_multiset<int>>);
60
61 static_assert(std::is_same_v<
62 decltype(std::unordered_multiset{{1, 2, 3},
63 {}, {}, {}, SimpleAllocator<int>{}}),
64 std::unordered_multiset<int, std::hash<int>,
65 std::equal_to<int>,
66 SimpleAllocator<int>>>);
67
68 void f()
69 {
70 std::unordered_multiset<int> x;
71
72 static_assert(std::is_same_v<
73 decltype(std::unordered_multiset(x.begin(), x.end())),
74 std::unordered_multiset<int>>);
75
76 static_assert(std::is_same_v<
77 decltype(std::unordered_multiset{x.begin(), x.end(),
78 {},
79 std::hash<int>{},
80 std::equal_to<int>{},
81 std::allocator<int>{}}),
82 std::unordered_multiset<int>>);
83
84 static_assert(std::is_same_v<
85 decltype(std::unordered_multiset{x.begin(), x.end(),
86 {}, std::hash<int>{}, std::equal_to<int>{}}),
87 std::unordered_multiset<int>>);
88
89 static_assert(std::is_same_v<
90 decltype(std::unordered_multiset{x.begin(), x.end(),
91 {}, std::hash<int>{}, std::allocator<int>{}}),
92 std::unordered_multiset<int>>);
93
94 static_assert(std::is_same_v<
95 decltype(std::unordered_multiset(x.begin(), x.end(),
96 {})),
97 std::unordered_multiset<int>>);
98
99 static_assert(std::is_same_v<
100 decltype(std::unordered_multiset{x.begin(), x.end(), 1}),
101 std::unordered_multiset<int>>);
102
103 static_assert(std::is_same_v<
104 decltype(std::unordered_multiset{x.begin(), x.end(),
105 1,
106 std::allocator<int>{}}),
107 std::unordered_multiset<int>>);
108
109 static_assert(std::is_same_v<
110 decltype(std::unordered_multiset{x.begin(), x.end(),
111 1,
112 SimpleAllocator<int>{}}),
113 std::unordered_multiset<int, std::hash<int>,
114 std::equal_to<int>,
115 SimpleAllocator<int>>>);
116
117 static_assert(std::is_same_v<
118 decltype(std::unordered_multiset{x.begin(), x.end(),
119 1, std::hash<int>{},
120 std::allocator<int>{}}),
121 std::unordered_multiset<int>>);
122
123 static_assert(std::is_same_v<
124 decltype(std::unordered_multiset{x.begin(), x.end(),
125 1, std::hash<int>{},
126 SimpleAllocator<int>{}}),
127 std::unordered_multiset<int, std::hash<int>,
128 std::equal_to<int>,
129 SimpleAllocator<int>>>);
130
131 static_assert(std::is_same_v<
132 decltype(std::unordered_multiset{x.begin(), x.end(),
133 {}, {}, {},
134 std::allocator<int>{}}),
135 std::unordered_multiset<int>>);
136
137 static_assert(std::is_same_v<
138 decltype(std::unordered_multiset{x.begin(), x.end(),
139 {}, {}, {},
140 SimpleAllocator<int>{}}),
141 std::unordered_multiset<int, std::hash<int>,
142 std::equal_to<int>,
143 SimpleAllocator<int>>>);
144 }
145
146 template<typename T, typename U> struct require_same;
147 template<typename T> struct require_same<T, T> { using type = void; };
148
149 template<typename T, typename U>
150 typename require_same<T, U>::type
151 check_type(U&) { }
152
153 struct Pool;
154
155 template<typename T>
156 struct Alloc : __gnu_test::SimpleAllocator<T>
157 {
158 Alloc(Pool*) { }
159
160 template<typename U>
161 Alloc(const Alloc<U>&) { }
162 };
163
164 void
165 test_p1518r2()
166 {
167 // P1518R2 - Stop overconstraining allocators in container deduction guides.
168 // This is a C++23 feature but we support it for C++17 too.
169
170 using Hash = std::hash<unsigned long>;
171 using Eq = std::equal_to<>;
172 using UMSet = std::unordered_multiset<unsigned, Hash, Eq, Alloc<unsigned>>;
173 Pool* p = nullptr;
174 UMSet s(p);
175
176 std::unordered_multiset s1(s, p);
177 check_type<UMSet>(s1);
178
179 std::unordered_multiset s2(std::move(s), p);
180 check_type<UMSet>(s2);
181 }