vect: Fix wrong code with pr108692.c on targets with only non-widening ABD [PR118727]
[gcc.git] / libstdc++-v3 / testsuite / 23_containers / multimap / cons / deduction.cc
blobf0699e2eefc38fc95e455dd30febe596050b920b
1 // { dg-do compile { target c++17 } }
3 #include <map>
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}},
39 {}}),
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}},
45 std::less<int>{}}),
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>>>);
60 void f()
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(),
69 std::less<int>{},
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(),
80 std::less<int>{})),
81 std::multimap<int, double>>);
83 static_assert(std::is_same_v<
84 decltype(std::multimap{x.begin(), x.end(),
85 {},
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(),
91 {},
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;
100 void g()
102 value_type array[1];
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(),
111 std::less<int>{},
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(),
122 std::less<int>{})),
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>>>);
139 void h()
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(),
150 std::less<int>{},
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(),
161 std::less<int>{})),
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
183 check_type(U&) { }
185 struct Pool;
187 template<typename T>
188 struct Alloc : __gnu_test::SimpleAllocator<T>
190 Alloc(Pool*) { }
192 template<typename U>
193 Alloc(const Alloc<U>&) { }
196 void
197 test_p1518r2()
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>;
204 Pool* p = nullptr;
205 MMap m(p);
207 std::multimap s1(m, p);
208 check_type<MMap>(s1);
210 std::multimap s2(std::move(m), p);
211 check_type<MMap>(s2);