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(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 | { |
30 | typedef std::unordered_multimap<int, Emplaceable> C; |
31 | typedef C::iterator R; |
32 | C c; |
33 | R r = c.emplace(std::piecewise_construct, std::forward_as_tuple(args: 3), |
34 | std::forward_as_tuple()); |
35 | assert(c.size() == 1); |
36 | assert(r->first == 3); |
37 | assert(r->second == Emplaceable()); |
38 | |
39 | r = c.emplace(std::pair<const int, Emplaceable>(4, Emplaceable(5, 6))); |
40 | assert(c.size() == 2); |
41 | assert(r->first == 4); |
42 | assert(r->second == Emplaceable(5, 6)); |
43 | |
44 | r = c.emplace(std::piecewise_construct, std::forward_as_tuple(args: 5), |
45 | std::forward_as_tuple(args: 6, args: 7)); |
46 | assert(c.size() == 3); |
47 | assert(r->first == 5); |
48 | assert(r->second == Emplaceable(6, 7)); |
49 | } |
50 | { |
51 | typedef std::unordered_multimap<int, Emplaceable, std::hash<int>, std::equal_to<int>, |
52 | min_allocator<std::pair<const int, Emplaceable>>> C; |
53 | typedef C::iterator R; |
54 | C c; |
55 | R r = c.emplace(std::piecewise_construct, std::forward_as_tuple(args: 3), |
56 | std::forward_as_tuple()); |
57 | assert(c.size() == 1); |
58 | assert(r->first == 3); |
59 | assert(r->second == Emplaceable()); |
60 | |
61 | r = c.emplace(std::pair<const int, Emplaceable>(4, Emplaceable(5, 6))); |
62 | assert(c.size() == 2); |
63 | assert(r->first == 4); |
64 | assert(r->second == Emplaceable(5, 6)); |
65 | |
66 | r = c.emplace(std::piecewise_construct, std::forward_as_tuple(args: 5), |
67 | std::forward_as_tuple(args: 6, args: 7)); |
68 | assert(c.size() == 3); |
69 | assert(r->first == 5); |
70 | assert(r->second == Emplaceable(6, 7)); |
71 | } |
72 | |
73 | return 0; |
74 | } |
75 | |