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 | #include <unordered_map> |
21 | #include <cassert> |
22 | |
23 | #include "test_macros.h" |
24 | #include "../../../Emplaceable.h" |
25 | #include "min_allocator.h" |
26 | |
27 | int main(int, char**) { |
28 | { |
29 | typedef std::unordered_map<int, Emplaceable> C; |
30 | typedef C::iterator R; |
31 | C c; |
32 | C::const_iterator e = c.end(); |
33 | R r = c.emplace_hint(e, std::piecewise_construct, std::forward_as_tuple(args: 3), std::forward_as_tuple()); |
34 | assert(c.size() == 1); |
35 | assert(r->first == 3); |
36 | assert(r->second == Emplaceable()); |
37 | |
38 | r = c.emplace_hint(c.end(), std::pair<const int, Emplaceable>(4, Emplaceable(5, 6))); |
39 | assert(c.size() == 2); |
40 | assert(r->first == 4); |
41 | assert(r->second == Emplaceable(5, 6)); |
42 | |
43 | r = c.emplace_hint(c.end(), std::piecewise_construct, std::forward_as_tuple(args: 5), std::forward_as_tuple(args: 6, args: 7)); |
44 | assert(c.size() == 3); |
45 | assert(r->first == 5); |
46 | assert(r->second == Emplaceable(6, 7)); |
47 | } |
48 | { |
49 | typedef std::unordered_map<int, |
50 | Emplaceable, |
51 | std::hash<int>, |
52 | std::equal_to<int>, |
53 | min_allocator<std::pair<const int, Emplaceable>>> |
54 | 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), std::forward_as_tuple()); |
59 | assert(c.size() == 1); |
60 | assert(r->first == 3); |
61 | assert(r->second == Emplaceable()); |
62 | |
63 | r = c.emplace_hint(c.end(), std::pair<const int, Emplaceable>(4, Emplaceable(5, 6))); |
64 | assert(c.size() == 2); |
65 | assert(r->first == 4); |
66 | assert(r->second == Emplaceable(5, 6)); |
67 | |
68 | r = c.emplace_hint(c.end(), std::piecewise_construct, std::forward_as_tuple(args: 5), std::forward_as_tuple(args: 6, args: 7)); |
69 | assert(c.size() == 3); |
70 | assert(r->first == 5); |
71 | assert(r->second == Emplaceable(6, 7)); |
72 | } |
73 | |
74 | return 0; |
75 | } |
76 | |