1 | //===----------------------------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // UNSUPPORTED: c++03 |
10 | |
11 | // <unordered_map> |
12 | |
13 | // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, |
14 | // class Alloc = allocator<pair<const Key, T>>> |
15 | // class unordered_map |
16 | |
17 | // template <class... Args> |
18 | // iterator emplace_hint(const_iterator p, Args&&... args); |
19 | |
20 | |
21 | #include <unordered_map> |
22 | #include <cassert> |
23 | |
24 | #include "test_macros.h" |
25 | #include "../../../Emplaceable.h" |
26 | #include "min_allocator.h" |
27 | |
28 | int main(int, char**) |
29 | { |
30 | { |
31 | typedef std::unordered_map<int, Emplaceable> C; |
32 | typedef C::iterator R; |
33 | C c; |
34 | C::const_iterator e = c.end(); |
35 | R r = c.emplace_hint(e, std::piecewise_construct, std::forward_as_tuple(args: 3), |
36 | std::forward_as_tuple()); |
37 | assert(c.size() == 1); |
38 | assert(r->first == 3); |
39 | assert(r->second == Emplaceable()); |
40 | |
41 | r = c.emplace_hint(c.end(), std::pair<const int, Emplaceable>(4, Emplaceable(5, 6))); |
42 | assert(c.size() == 2); |
43 | assert(r->first == 4); |
44 | assert(r->second == Emplaceable(5, 6)); |
45 | |
46 | r = c.emplace_hint(c.end(), std::piecewise_construct, std::forward_as_tuple(args: 5), |
47 | std::forward_as_tuple(args: 6, args: 7)); |
48 | assert(c.size() == 3); |
49 | assert(r->first == 5); |
50 | assert(r->second == Emplaceable(6, 7)); |
51 | } |
52 | { |
53 | typedef std::unordered_map<int, Emplaceable, std::hash<int>, std::equal_to<int>, |
54 | min_allocator<std::pair<const int, Emplaceable>>> C; |
55 | typedef C::iterator R; |
56 | C c; |
57 | C::const_iterator e = c.end(); |
58 | R r = c.emplace_hint(e, std::piecewise_construct, std::forward_as_tuple(args: 3), |
59 | std::forward_as_tuple()); |
60 | assert(c.size() == 1); |
61 | assert(r->first == 3); |
62 | assert(r->second == Emplaceable()); |
63 | |
64 | r = c.emplace_hint(c.end(), std::pair<const int, Emplaceable>(4, Emplaceable(5, 6))); |
65 | assert(c.size() == 2); |
66 | assert(r->first == 4); |
67 | assert(r->second == Emplaceable(5, 6)); |
68 | |
69 | r = c.emplace_hint(c.end(), std::piecewise_construct, std::forward_as_tuple(args: 5), |
70 | std::forward_as_tuple(args: 6, args: 7)); |
71 | assert(c.size() == 3); |
72 | assert(r->first == 5); |
73 | assert(r->second == Emplaceable(6, 7)); |
74 | } |
75 | |
76 | return 0; |
77 | } |
78 | |