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_multimap |
16 | |
17 | // template <class... Args> |
18 | // iterator emplace_hint(const_iterator p, Args&&... args); |
19 | |
20 | |
21 | #include <unordered_map> |
22 | #include <cassert> |
23 | #include <iterator> |
24 | |
25 | #include "../../../Emplaceable.h" |
26 | #include "min_allocator.h" |
27 | #include "test_macros.h" |
28 | |
29 | int main(int, char**) |
30 | { |
31 | { |
32 | typedef std::unordered_multimap<int, Emplaceable> C; |
33 | typedef C::iterator R; |
34 | C c; |
35 | C::const_iterator e = c.end(); |
36 | R r = c.emplace_hint(e, std::piecewise_construct, std::forward_as_tuple(args: 3), |
37 | std::forward_as_tuple()); |
38 | assert(c.size() == 1); |
39 | assert(r->first == 3); |
40 | assert(r->second == Emplaceable()); |
41 | |
42 | r = c.emplace_hint(c.end(), std::pair<const int, Emplaceable>(3, Emplaceable(5, 6))); |
43 | assert(c.size() == 2); |
44 | assert(r->first == 3); |
45 | assert(r->second == Emplaceable(5, 6)); |
46 | LIBCPP_ASSERT(r == std::next(c.begin())); |
47 | |
48 | r = c.emplace_hint(r, std::piecewise_construct, std::forward_as_tuple(args: 3), |
49 | std::forward_as_tuple(args: 6, args: 7)); |
50 | assert(c.size() == 3); |
51 | assert(r->first == 3); |
52 | assert(r->second == Emplaceable(6, 7)); |
53 | LIBCPP_ASSERT(r == std::next(c.begin())); |
54 | r = c.begin(); |
55 | assert(r->first == 3); |
56 | LIBCPP_ASSERT(r->second == Emplaceable()); |
57 | r = std::next(r, 2); |
58 | assert(r->first == 3); |
59 | LIBCPP_ASSERT(r->second == Emplaceable(5, 6)); |
60 | } |
61 | { |
62 | typedef std::unordered_multimap<int, Emplaceable, std::hash<int>, std::equal_to<int>, |
63 | min_allocator<std::pair<const int, Emplaceable>>> C; |
64 | typedef C::iterator R; |
65 | C c; |
66 | C::const_iterator e = c.end(); |
67 | R r = c.emplace_hint(e, std::piecewise_construct, std::forward_as_tuple(args: 3), |
68 | std::forward_as_tuple()); |
69 | assert(c.size() == 1); |
70 | assert(r->first == 3); |
71 | assert(r->second == Emplaceable()); |
72 | |
73 | r = c.emplace_hint(c.end(), std::pair<const int, Emplaceable>(3, Emplaceable(5, 6))); |
74 | assert(c.size() == 2); |
75 | assert(r->first == 3); |
76 | assert(r->second == Emplaceable(5, 6)); |
77 | LIBCPP_ASSERT(r == std::next(c.begin())); |
78 | |
79 | r = c.emplace_hint(r, std::piecewise_construct, std::forward_as_tuple(args: 3), |
80 | std::forward_as_tuple(args: 6, args: 7)); |
81 | assert(c.size() == 3); |
82 | assert(r->first == 3); |
83 | assert(r->second == Emplaceable(6, 7)); |
84 | LIBCPP_ASSERT(r == std::next(c.begin())); |
85 | r = c.begin(); |
86 | assert(r->first == 3); |
87 | LIBCPP_ASSERT(r->second == Emplaceable()); |
88 | r = std::next(r, 2); |
89 | assert(r->first == 3); |
90 | LIBCPP_ASSERT(r->second == Emplaceable(5, 6)); |
91 | } |
92 | |
93 | return 0; |
94 | } |
95 | |