2 // Copyright 2017-2018 Daniel James.
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #include <boost/unordered_map.hpp>
10 #if BOOST_UNORDERED_TEMPLATE_DEDUCTION_GUIDES
13 template <typename T
> bool operator()(T
const& x
) const
19 template <typename T
> bool operator()(T
const& x
, T
const& y
) const
26 template <typename T
> struct test_allocator
29 test_allocator() = default;
30 template <typename T2
> test_allocator(test_allocator
<T2
> const&) {}
31 T
* allocate(std::size_t n
) const { return (T
*)malloc(sizeof(T
) * n
); }
32 void deallocate(T
* ptr
, std::size_t) const { free(ptr
); }
33 bool operator==(test_allocator
const&) const { return true; }
34 bool operator!=(test_allocator
const&) const { return false; }
40 std::cout
<< "BOOST_UNORDERED_TEMPLATE_DEDUCTION_GUIDES: "
41 << BOOST_UNORDERED_TEMPLATE_DEDUCTION_GUIDES
<< std::endl
;
43 #if BOOST_UNORDERED_TEMPLATE_DEDUCTION_GUIDES
44 std::vector
<std::pair
<int, int> > x
;
45 x
.push_back(std::make_pair(1, 3));
46 x
.push_back(std::make_pair(5, 10));
47 test_allocator
<std::pair
<const int, int> > pair_allocator
;
53 template<class InputIterator,
54 class Hash = hash<iter_key_t<InputIterator>>,
55 class Pred = equal_to<iter_key_t<InputIterator>>,
56 class Allocator = allocator<iter_to_alloc_t<InputIterator>>>
57 unordered_map(InputIterator, InputIterator, typename see below::size_type =
59 Hash = Hash(), Pred = Pred(), Allocator = Allocator())
60 -> unordered_map<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
66 boost::unordered_map
m(x
.begin(), x
.end());
68 std::is_same
<decltype(m
), boost::unordered_map
<int, int> >::value
);
73 boost::unordered_map m(x.begin(), x.end(), 0, std::hash<int>());
74 static_assert(std::is_same<decltype(m),boost::unordered_map<int, int,
75 std::hash<int>>>::value);
79 boost::unordered_map m(x.begin(), x.end(), 0, std::hash<int>(),
80 std::equal_to<int>());
81 static_assert(std::is_same<decltype(m),boost::unordered_map<int, int,
82 std::hash<int>, std::equal_to<int>>>::value);
87 boost::unordered_map
m(x
.begin(), x
.end(), 0, std::hash
<int>(),
88 std::equal_to
<int>(), pair_allocator
);
89 static_assert(std::is_same
<decltype(m
),
90 boost::unordered_map
<int, int, std::hash
<int>, std::equal_to
<int>,
91 test_allocator
<std::pair
<const int, int> > > >::value
);
95 template<class Key, class T, class Hash = hash<Key>,
96 class Pred = equal_to<Key>, class Allocator = allocator<pair<const
98 unordered_map(initializer_list<pair<const Key, T>>,
99 typename see below::size_type = see below, Hash = Hash(),
100 Pred = Pred(), Allocator = Allocator())
101 -> unordered_map<Key, T, Hash, Pred, Allocator>;
105 boost::unordered_map
m({std::pair
<int const, int>(1, 2)});
107 std::is_same
<decltype(m
), boost::unordered_map
<int, int> >::value
);
112 boost::unordered_map m({std::pair<int const, int>(1,2)}, 0,
114 static_assert(std::is_same<decltype(m),boost::unordered_map<int, int,
115 std::hash<int>>>::value);
119 boost::unordered_map m({std::pair<int const, int>(1,2)}, 0,
120 std::hash<int>(), std::equal_to<int>());
121 static_assert(std::is_same<decltype(m),boost::unordered_map<int, int,
122 std::hash<int>, std::equal_to<int>>>::value);
127 boost::unordered_map
m(
128 {std::pair
<int const, int>(1, 2)}, 0, f
, f
, pair_allocator
);
129 static_assert(std::is_same
<decltype(m
),
130 boost::unordered_map
<int, int, hash_equals
, hash_equals
,
131 test_allocator
<std::pair
<const int, int> > > >::value
);
135 template<class InputIterator, class Allocator>
136 unordered_map(InputIterator, InputIterator, typename see below::size_type,
138 -> unordered_map<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
139 hash<iter_key_t<InputIterator>>,
140 equal_to<iter_key_t<InputIterator>>,
146 boost::unordered_map m(x.begin(), x.end(), 0u, pair_allocator);
147 static_assert(std::is_same<decltype(m), boost::unordered_map<int, int,
148 boost::hash<int>, std::equal_to<int>, test_allocator<std::pair<const int,
154 template<class InputIterator, class Allocator>
155 unordered_map(InputIterator, InputIterator, Allocator)
156 -> unordered_map<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
157 hash<iter_key_t<InputIterator>>,
158 equal_to<iter_key_t<InputIterator>>,
164 boost::unordered_map m(x.begin(), x.end(), pair_allocator);
165 static_assert(std::is_same<decltype(m), boost::unordered_map<int, int,
166 boost::hash<int>, std::equal_to<int>, test_allocator<std::pair<const int,
172 template<class InputIterator, class Hash, class Allocator>
173 unordered_map(InputIterator, InputIterator, typename see below::size_type,
175 -> unordered_map<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
177 equal_to<iter_key_t<InputIterator>>, Allocator>;
182 boost::unordered_map m(x.begin(), x.end(), 0u, f, pair_allocator);
183 static_assert(std::is_same<decltype(m), boost::unordered_map<int, int,
184 hash_equals, std::equal_to<int>, test_allocator<std::pair<const int,
190 template<class Key, class T, typename Allocator>
191 unordered_map(initializer_list<pair<const Key, T>>, typename see
194 -> unordered_map<Key, T, hash<Key>, equal_to<Key>, Allocator>;
199 boost::unordered_map m({std::pair<int const, int>(1,2)}, 0, pair_allocator);
200 static_assert(std::is_same<decltype(m),boost::unordered_map<int, int,
201 boost::hash<int>, std::equal_to<int>, test_allocator<std::pair<const int,
207 template<class Key, class T, typename Allocator>
208 unordered_map(initializer_list<pair<const Key, T>>, Allocator)
209 -> unordered_map<Key, T, hash<Key>, equal_to<Key>, Allocator>;
213 boost::unordered_map
m({std::pair
<int const, int>(1, 2)}, pair_allocator
);
214 static_assert(std::is_same
<decltype(m
),
215 boost::unordered_map
<int, int, boost::hash
<int>, std::equal_to
<int>,
216 test_allocator
<std::pair
<const int, int> > > >::value
);
220 template<class Key, class T, class Hash, class Allocator>
221 unordered_map(initializer_list<pair<const Key, T>>, typename see
222 below::size_type, Hash,
224 -> unordered_map<Key, T, Hash, equal_to<Key>, Allocator>;
229 boost::unordered_map m({std::pair<int const, int>(1,2)}, 0, f,
231 static_assert(std::is_same<decltype(m),boost::unordered_map<int, int,
232 boost::hash<int>, std::equal_to<int>, test_allocator<std::pair<const int,
237 // unordered_multimap
240 boost::unordered_multimap
m(x
.begin(), x
.end());
242 std::is_same
<decltype(m
), boost::unordered_multimap
<int, int> >::value
);
247 boost::unordered_multimap m(x.begin(), x.end(), 0, std::hash<int>());
248 static_assert(std::is_same<decltype(m),boost::unordered_multimap<int, int,
249 std::hash<int>>>::value);
253 boost::unordered_multimap m(x.begin(), x.end(), 0, std::hash<int>(),
254 std::equal_to<int>());
255 static_assert(std::is_same<decltype(m),boost::unordered_multimap<int, int,
256 std::hash<int>, std::equal_to<int>>>::value);
261 boost::unordered_multimap
m(x
.begin(), x
.end(), 0, std::hash
<int>(),
262 std::equal_to
<int>(), pair_allocator
);
263 static_assert(std::is_same
<decltype(m
),
264 boost::unordered_multimap
<int, int, std::hash
<int>, std::equal_to
<int>,
265 test_allocator
<std::pair
<const int, int> > > >::value
);
269 boost::unordered_multimap
m({std::pair
<int const, int>(1, 2)});
271 std::is_same
<decltype(m
), boost::unordered_multimap
<int, int> >::value
);
276 boost::unordered_multimap m({std::pair<int const, int>(1,2)}, 0,
278 static_assert(std::is_same<decltype(m),boost::unordered_multimap<int, int,
279 std::hash<int>>>::value);
283 boost::unordered_multimap m({std::pair<int const, int>(1,2)}, 0,
284 std::hash<int>(), std::equal_to<int>());
285 static_assert(std::is_same<decltype(m),boost::unordered_multimap<int, int,
286 std::hash<int>, std::equal_to<int>>>::value);
291 boost::unordered_multimap
m(
292 {std::pair
<int const, int>(1, 2)}, 0, f
, f
, pair_allocator
);
293 static_assert(std::is_same
<decltype(m
),
294 boost::unordered_multimap
<int, int, hash_equals
, hash_equals
,
295 test_allocator
<std::pair
<const int, int> > > >::value
);
300 boost::unordered_multimap m(x.begin(), x.end(), 0u, pair_allocator);
301 static_assert(std::is_same<decltype(m), boost::unordered_multimap<int, int,
302 boost::hash<int>, std::equal_to<int>, test_allocator<std::pair<const int,
309 boost::unordered_multimap m(x.begin(), x.end(), pair_allocator);
310 static_assert(std::is_same<decltype(m), boost::unordered_multimap<int, int,
311 boost::hash<int>, std::equal_to<int>, test_allocator<std::pair<const int,
318 boost::unordered_multimap m(x.begin(), x.end(), 0u, f, pair_allocator);
319 static_assert(std::is_same<decltype(m), boost::unordered_multimap<int, int,
320 hash_equals, std::equal_to<int>, test_allocator<std::pair<const int,
325 boost::unordered_multimap m({std::pair<int const, int>(1,2)}, 0,
327 static_assert(std::is_same<decltype(m),boost::unordered_multimap<int, int,
328 boost::hash<int>, std::equal_to<int>, test_allocator<std::pair<const int,
334 boost::unordered_multimap
m(
335 {std::pair
<int const, int>(1, 2)}, pair_allocator
);
336 static_assert(std::is_same
<decltype(m
),
337 boost::unordered_multimap
<int, int, boost::hash
<int>, std::equal_to
<int>,
338 test_allocator
<std::pair
<const int, int> > > >::value
);
343 boost::unordered_multimap m({std::pair<int const, int>(1,2)}, 0, f,
345 static_assert(std::is_same<decltype(m),boost::unordered_multimap<int, int,
346 boost::hash<int>, std::equal_to<int>, test_allocator<std::pair<const int,