1 // { dg-do compile { target c++17 } }
3 #include <unordered_set>
4 #include <testsuite_allocator.h>
6 using __gnu_test::SimpleAllocator
;
8 static_assert(std::is_same_v
<
9 decltype(std::unordered_set
{1, 2, 3}),
10 std::unordered_set
<int>>);
12 static_assert(std::is_same_v
<
13 decltype(std::unordered_set
{{1, 2, 3},
14 0, std::hash
<int>{}, std::equal_to
<int>{}}),
15 std::unordered_set
<int>>);
17 static_assert(std::is_same_v
<
18 decltype(std::unordered_set
{{1, 2, 3},
19 0, std::hash
<int>{}, std::allocator
<int>{}}),
20 std::unordered_set
<int>>);
22 static_assert(std::is_same_v
<
23 decltype(std::unordered_set
{{1, 2, 3},
25 std::unordered_set
<int>>);
27 static_assert(std::is_same_v
<
28 decltype(std::unordered_set
{{1, 2, 3},
29 1, std::allocator
<int>{}}),
30 std::unordered_set
<int>>);
32 static_assert(std::is_same_v
<
33 decltype(std::unordered_set
{{1, 2, 3},
34 1, SimpleAllocator
<int>{}}),
35 std::unordered_set
<int, std::hash
<int>,
37 SimpleAllocator
<int>>>);
39 static_assert(std::is_same_v
<
40 decltype(std::unordered_set
{{1, 2, 3},
41 1, std::hash
<int>{}, std::allocator
<int>{}}),
42 std::unordered_set
<int>>);
44 static_assert(std::is_same_v
<
45 decltype(std::unordered_set
{{1, 2, 3},
46 1, std::hash
<int>{}, SimpleAllocator
<int>{}}),
47 std::unordered_set
<int, std::hash
<int>,
49 SimpleAllocator
<int>>>);
51 static_assert(std::is_same_v
<
52 decltype(std::unordered_set
{{1, 2, 3},
53 {}, {}, {}, std::allocator
<int>{}}),
54 std::unordered_set
<int>>);
56 static_assert(std::is_same_v
<
57 decltype(std::unordered_set
{{1, 2, 3},
58 {}, {}, {}, SimpleAllocator
<int>{}}),
59 std::unordered_set
<int, std::hash
<int>,
61 SimpleAllocator
<int>>>);
65 std::unordered_set
<int> x
;
67 static_assert(std::is_same_v
<
68 decltype(std::unordered_set(x
.begin(), x
.end())),
69 std::unordered_set
<int>>);
71 static_assert(std::is_same_v
<
72 decltype(std::unordered_set
{x
.begin(), x
.end(),
76 std::allocator
<int>{}}),
77 std::unordered_set
<int>>);
79 static_assert(std::is_same_v
<
80 decltype(std::unordered_set
{x
.begin(), x
.end(),
81 {}, std::hash
<int>{}, std::equal_to
<int>{}}),
82 std::unordered_set
<int>>);
84 static_assert(std::is_same_v
<
85 decltype(std::unordered_set
{x
.begin(), x
.end(),
86 {}, std::hash
<int>{}, std::allocator
<int>{}}),
87 std::unordered_set
<int>>);
89 static_assert(std::is_same_v
<
90 decltype(std::unordered_set(x
.begin(), x
.end(),
92 std::unordered_set
<int>>);
94 static_assert(std::is_same_v
<
95 decltype(std::unordered_set
{x
.begin(), x
.end(), 1}),
96 std::unordered_set
<int>>);
98 static_assert(std::is_same_v
<
99 decltype(std::unordered_set
{x
.begin(), x
.end(),
101 std::allocator
<int>{}}),
102 std::unordered_set
<int>>);
104 static_assert(std::is_same_v
<
105 decltype(std::unordered_set
{x
.begin(), x
.end(),
107 SimpleAllocator
<int>{}}),
108 std::unordered_set
<int, std::hash
<int>,
110 SimpleAllocator
<int>>>);
112 static_assert(std::is_same_v
<
113 decltype(std::unordered_set
{x
.begin(), x
.end(),
115 std::allocator
<int>{}}),
116 std::unordered_set
<int>>);
118 static_assert(std::is_same_v
<
119 decltype(std::unordered_set
{x
.begin(), x
.end(),
121 SimpleAllocator
<int>{}}),
122 std::unordered_set
<int, std::hash
<int>,
124 SimpleAllocator
<int>>>);
126 static_assert(std::is_same_v
<
127 decltype(std::unordered_set
{x
.begin(), x
.end(),
129 std::allocator
<int>{}}),
130 std::unordered_set
<int>>);
132 static_assert(std::is_same_v
<
133 decltype(std::unordered_set
{x
.begin(), x
.end(),
135 SimpleAllocator
<int>{}}),
136 std::unordered_set
<int, std::hash
<int>,
138 SimpleAllocator
<int>>>);
141 template<typename T
, typename U
> struct require_same
;
142 template<typename T
> struct require_same
<T
, T
> { using type
= void; };
144 template<typename T
, typename U
>
145 typename require_same
<T
, U
>::type
151 struct Alloc
: __gnu_test::SimpleAllocator
<T
>
156 Alloc(const Alloc
<U
>&) { }
162 // P1518R2 - Stop overconstraining allocators in container deduction guides.
163 // This is a C++23 feature but we support it for C++17 too.
165 using Hash
= std::hash
<unsigned long>;
166 using Eq
= std::equal_to
<>;
167 using USet
= std::unordered_set
<unsigned, Hash
, Eq
, Alloc
<unsigned>>;
171 std::unordered_set
s1(s
, p
);
172 check_type
<USet
>(s1
);
174 std::unordered_set
s2(std::move(s
), p
);
175 check_type
<USet
>(s2
);