1 // { dg-do compile { target c++17 } }
4 #include <testsuite_allocator.h>
5 #include <testsuite_iterators.h>
7 using __gnu_test::SimpleAllocator
;
8 using value_type
= std::multimap
<int, double>::value_type
;
10 static_assert(std::is_same_v
<
11 decltype(std::multimap
{value_type
{1, 2.0}, {2, 3.0}, {3, 4.0}}),
12 std::multimap
<int, double>>);
14 static_assert(std::is_same_v
<
15 decltype(std::multimap
{std::pair
{1, 2.0}, {2, 3.0}, {3, 4.0}}),
16 std::multimap
<int, double>>);
18 static_assert(std::is_same_v
<
19 decltype(std::multimap
{{value_type
{1, 2.0}, {2, 3.0}, {3, 4.0}}}),
20 std::multimap
<int, double>>);
22 static_assert(std::is_same_v
<
23 decltype(std::multimap
{{std::pair
{1, 2.0}, {2, 3.0}, {3, 4.0}}}),
24 std::multimap
<int, double>>);
26 static_assert(std::is_same_v
<
27 decltype(std::multimap
{{value_type
{1, 2.0}, {2, 3.0}, {3, 4.0}},
28 std::less
<int>{}, {}}),
29 std::multimap
<int, double>>);
31 static_assert(std::is_same_v
<
32 decltype(std::multimap
{{std::pair
{1, 2.0}, {2, 3.0}, {3, 4.0}},
33 std::less
<int>{}, {}}),
34 std::multimap
<int, double>>);
36 /* This is not deducible, {} could be deduced as _Compare or _Allocator.
37 static_assert(std::is_same_v<
38 decltype(std::multimap{{value_type{1, 2.0}, {2, 3.0}, {3, 4.0}},
40 std::multimap<int, double>>);
43 static_assert(std::is_same_v
<
44 decltype(std::multimap
{{std::pair
{1, 2.0}, {2, 3.0}, {3, 4.0}},
46 std::multimap
<int, double>>);
48 static_assert(std::is_same_v
<
49 decltype(std::multimap
{{value_type
{1, 2.0}, {2, 3.0}, {3, 4.0}},
50 {}, SimpleAllocator
<value_type
>{}}),
51 std::multimap
<int, double, std::less
<int>,
52 SimpleAllocator
<value_type
>>>);
54 static_assert(std::is_same_v
<
55 decltype(std::multimap
{{std::pair
{1, 2.0}, {2, 3.0}, {3, 4.0}},
56 {}, SimpleAllocator
<value_type
>{}}),
57 std::multimap
<int, double, std::less
<int>,
58 SimpleAllocator
<value_type
>>>);
62 std::multimap
<int, double> x
;
63 static_assert(std::is_same_v
<
64 decltype(std::multimap(x
.begin(), x
.end())),
65 std::multimap
<int, double>>);
67 static_assert(std::is_same_v
<
68 decltype(std::multimap
{x
.begin(), x
.end(),
70 std::allocator
<value_type
>{}}),
71 std::multimap
<int, double>>);
73 static_assert(std::is_same_v
<
74 decltype(std::multimap
{x
.begin(), x
.end(),
75 std::less
<int>{}, {}}),
76 std::multimap
<int, double>>);
78 static_assert(std::is_same_v
<
79 decltype(std::multimap(x
.begin(), x
.end(),
81 std::multimap
<int, double>>);
83 static_assert(std::is_same_v
<
84 decltype(std::multimap
{x
.begin(), x
.end(),
86 std::allocator
<value_type
>{}}),
87 std::multimap
<int, double>>);
89 static_assert(std::is_same_v
<
90 decltype(std::multimap
{x
.begin(), x
.end(),
92 SimpleAllocator
<value_type
>{}}),
93 std::multimap
<int, double, std::less
<int>,
94 SimpleAllocator
<value_type
>>>);
97 using __gnu_test::test_container
;
98 using __gnu_test::input_iterator_wrapper
;
103 test_container
<value_type
, input_iterator_wrapper
> x(array
);
105 static_assert(std::is_same_v
<
106 decltype(std::multimap(x
.begin(), x
.end())),
107 std::multimap
<int, double>>);
109 static_assert(std::is_same_v
<
110 decltype(std::multimap
{x
.begin(), x
.end(),
112 std::allocator
<value_type
>{}}),
113 std::multimap
<int, double>>);
115 static_assert(std::is_same_v
<
116 decltype(std::multimap
{x
.begin(), x
.end(),
117 std::less
<int>{}, {}}),
118 std::multimap
<int, double>>);
120 static_assert(std::is_same_v
<
121 decltype(std::multimap(x
.begin(), x
.end(),
123 std::multimap
<int, double>>);
125 static_assert(std::is_same_v
<
126 decltype(std::multimap
{x
.begin(), x
.end(),
128 std::allocator
<value_type
>{}}),
129 std::multimap
<int, double>>);
131 static_assert(std::is_same_v
<
132 decltype(std::multimap
{x
.begin(), x
.end(),
134 SimpleAllocator
<value_type
>{}}),
135 std::multimap
<int, double, std::less
<int>,
136 SimpleAllocator
<value_type
>>>);
141 std::pair
<int, double> array
[1];
142 test_container
<std::pair
<int, double>, input_iterator_wrapper
> x(array
);
144 static_assert(std::is_same_v
<
145 decltype(std::multimap(x
.begin(), x
.end())),
146 std::multimap
<int, double>>);
148 static_assert(std::is_same_v
<
149 decltype(std::multimap
{x
.begin(), x
.end(),
151 std::allocator
<value_type
>{}}),
152 std::multimap
<int, double>>);
154 static_assert(std::is_same_v
<
155 decltype(std::multimap
{x
.begin(), x
.end(),
156 std::less
<int>{}, {}}),
157 std::multimap
<int, double>>);
159 static_assert(std::is_same_v
<
160 decltype(std::multimap(x
.begin(), x
.end(),
162 std::multimap
<int, double>>);
164 static_assert(std::is_same_v
<
165 decltype(std::multimap
{x
.begin(), x
.end(),
167 std::allocator
<value_type
>{}}),
168 std::multimap
<int, double>>);
170 static_assert(std::is_same_v
<
171 decltype(std::multimap
{x
.begin(), x
.end(),
173 SimpleAllocator
<value_type
>{}}),
174 std::multimap
<int, double, std::less
<int>,
175 SimpleAllocator
<value_type
>>>);
178 template<typename T
, typename U
> struct require_same
;
179 template<typename T
> struct require_same
<T
, T
> { using type
= void; };
181 template<typename T
, typename U
>
182 typename require_same
<T
, U
>::type
188 struct Alloc
: __gnu_test::SimpleAllocator
<T
>
193 Alloc(const Alloc
<U
>&) { }
199 // P1518R2 - Stop overconstraining allocators in container deduction guides.
200 // This is a C++23 feature but we support it for C++17 too.
202 using PairAlloc
= Alloc
<std::pair
<const unsigned, void*>>;
203 using MMap
= std::multimap
<unsigned, void*, std::greater
<>, PairAlloc
>;
207 std::multimap
s1(m
, p
);
208 check_type
<MMap
>(s1
);
210 std::multimap
s2(std::move(m
), p
);
211 check_type
<MMap
>(s2
);