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 P,
18// class = typename enable_if<is_convertible<P, value_type>::value>::type>
19// iterator insert(P&& x);
20
21#include <unordered_map>
22#include <cassert>
23
24#include "test_macros.h"
25#include "MoveOnly.h"
26#include "min_allocator.h"
27
28int main(int, char**)
29{
30 {
31 typedef std::unordered_multimap<double, int> C;
32 typedef C::iterator R;
33 typedef std::pair<double, short> P;
34 C c;
35 R r = c.insert(x: P(3.5, static_cast<short>(3)));
36 assert(c.size() == 1);
37 assert(r->first == 3.5);
38 assert(r->second == 3);
39
40 r = c.insert(x: P(3.5, static_cast<short>(4)));
41 assert(c.size() == 2);
42 assert(r->first == 3.5);
43 assert(r->second == 4);
44
45 r = c.insert(x: P(4.5, static_cast<short>(4)));
46 assert(c.size() == 3);
47 assert(r->first == 4.5);
48 assert(r->second == 4);
49
50 r = c.insert(x: P(5.5, static_cast<short>(4)));
51 assert(c.size() == 4);
52 assert(r->first == 5.5);
53 assert(r->second == 4);
54 }
55 {
56 typedef std::unordered_multimap<MoveOnly, MoveOnly> C;
57 typedef C::iterator R;
58 typedef std::pair<MoveOnly, MoveOnly> P;
59 C c;
60 R r = c.insert(P(3, 3));
61 assert(c.size() == 1);
62 assert(r->first == 3);
63 assert(r->second == 3);
64
65 r = c.insert(P(3, 4));
66 assert(c.size() == 2);
67 assert(r->first == 3);
68 assert(r->second == 4);
69
70 r = c.insert(P(4, 4));
71 assert(c.size() == 3);
72 assert(r->first == 4);
73 assert(r->second == 4);
74
75 r = c.insert(P(5, 4));
76 assert(c.size() == 4);
77 assert(r->first == 5);
78 assert(r->second == 4);
79 }
80 {
81 typedef std::unordered_multimap<double, int, std::hash<double>, std::equal_to<double>,
82 min_allocator<std::pair<const double, int>>> C;
83 typedef C::iterator R;
84 typedef std::pair<double, short> P;
85 C c;
86 R r = c.insert(P(3.5, static_cast<short>(3)));
87 assert(c.size() == 1);
88 assert(r->first == 3.5);
89 assert(r->second == 3);
90
91 r = c.insert(P(3.5, static_cast<short>(4)));
92 assert(c.size() == 2);
93 assert(r->first == 3.5);
94 assert(r->second == 4);
95
96 r = c.insert(P(4.5, static_cast<short>(4)));
97 assert(c.size() == 3);
98 assert(r->first == 4.5);
99 assert(r->second == 4);
100
101 r = c.insert(P(5.5, static_cast<short>(4)));
102 assert(c.size() == 4);
103 assert(r->first == 5.5);
104 assert(r->second == 4);
105 }
106 {
107 typedef std::unordered_multimap<MoveOnly, MoveOnly, std::hash<MoveOnly>, std::equal_to<MoveOnly>,
108 min_allocator<std::pair<const MoveOnly, MoveOnly>>> C;
109 typedef C::iterator R;
110 typedef std::pair<MoveOnly, MoveOnly> P;
111 C c;
112 R r = c.insert(P(3, 3));
113 assert(c.size() == 1);
114 assert(r->first == 3);
115 assert(r->second == 3);
116
117 r = c.insert(P(3, 4));
118 assert(c.size() == 2);
119 assert(r->first == 3);
120 assert(r->second == 4);
121
122 r = c.insert(P(4, 4));
123 assert(c.size() == 3);
124 assert(r->first == 4);
125 assert(r->second == 4);
126
127 r = c.insert(P(5, 4));
128 assert(c.size() == 4);
129 assert(r->first == 5);
130 assert(r->second == 4);
131 }
132 {
133 typedef std::unordered_multimap<double, MoveOnly> C;
134 typedef C::iterator R;
135 C c;
136 R r = c.insert({3.5, 3});
137 assert(c.size() == 1);
138 assert(r->first == 3.5);
139 assert(r->second == 3);
140
141 r = c.insert({3.5, 4});
142 assert(c.size() == 2);
143 assert(r->first == 3.5);
144 assert(r->second == 4);
145
146 r = c.insert({4.5, 4});
147 assert(c.size() == 3);
148 assert(r->first == 4.5);
149 assert(r->second == 4);
150
151 r = c.insert({5.5, 4});
152 assert(c.size() == 4);
153 assert(r->first == 5.5);
154 assert(r->second == 4);
155 }
156
157 return 0;
158}
159

source code of libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_rvalue.pass.cpp