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 | // <map> |
12 | |
13 | // class multimap |
14 | |
15 | // template <class... Args> |
16 | // iterator emplace(Args&&... args); |
17 | |
18 | #include <map> |
19 | #include <cassert> |
20 | |
21 | #include "test_macros.h" |
22 | #include "../../../Emplaceable.h" |
23 | #include "DefaultOnly.h" |
24 | #include "min_allocator.h" |
25 | |
26 | int main(int, char**) |
27 | { |
28 | { |
29 | typedef std::multimap<int, DefaultOnly> M; |
30 | typedef M::iterator R; |
31 | M m; |
32 | assert(DefaultOnly::count == 0); |
33 | R r = m.emplace(); |
34 | assert(r == m.begin()); |
35 | assert(m.size() == 1); |
36 | assert(m.begin()->first == 0); |
37 | assert(m.begin()->second == DefaultOnly()); |
38 | assert(DefaultOnly::count == 1); |
39 | r = m.emplace(std::piecewise_construct, std::forward_as_tuple(args: 1), |
40 | std::forward_as_tuple()); |
41 | assert(r == std::next(m.begin())); |
42 | assert(m.size() == 2); |
43 | assert(std::next(m.begin())->first == 1); |
44 | assert(std::next(m.begin())->second == DefaultOnly()); |
45 | assert(DefaultOnly::count == 2); |
46 | r = m.emplace(std::piecewise_construct, std::forward_as_tuple(args: 1), |
47 | std::forward_as_tuple()); |
48 | assert(r == std::next(m.begin(), 2)); |
49 | assert(m.size() == 3); |
50 | assert(std::next(m.begin(), 2)->first == 1); |
51 | assert(std::next(m.begin(), 2)->second == DefaultOnly()); |
52 | assert(DefaultOnly::count == 3); |
53 | } |
54 | assert(DefaultOnly::count == 0); |
55 | { |
56 | typedef std::multimap<int, Emplaceable> M; |
57 | typedef M::iterator R; |
58 | M m; |
59 | R r = m.emplace(std::piecewise_construct, std::forward_as_tuple(args: 2), |
60 | std::forward_as_tuple()); |
61 | assert(r == m.begin()); |
62 | assert(m.size() == 1); |
63 | assert(m.begin()->first == 2); |
64 | assert(m.begin()->second == Emplaceable()); |
65 | r = m.emplace(std::piecewise_construct, std::forward_as_tuple(args: 1), |
66 | std::forward_as_tuple(args: 2, args: 3.5)); |
67 | assert(r == m.begin()); |
68 | assert(m.size() == 2); |
69 | assert(m.begin()->first == 1); |
70 | assert(m.begin()->second == Emplaceable(2, 3.5)); |
71 | r = m.emplace(std::piecewise_construct, std::forward_as_tuple(args: 1), |
72 | std::forward_as_tuple(args: 3, args: 3.5)); |
73 | assert(r == std::next(m.begin())); |
74 | assert(m.size() == 3); |
75 | assert(r->first == 1); |
76 | assert(r->second == Emplaceable(3, 3.5)); |
77 | } |
78 | { |
79 | typedef std::multimap<int, double> M; |
80 | typedef M::iterator R; |
81 | M m; |
82 | R r = m.emplace(args: M::value_type(2, 3.5)); |
83 | assert(r == m.begin()); |
84 | assert(m.size() == 1); |
85 | assert(m.begin()->first == 2); |
86 | assert(m.begin()->second == 3.5); |
87 | } |
88 | { |
89 | typedef std::multimap<int, DefaultOnly, std::less<int>, min_allocator<std::pair<const int, DefaultOnly>>> M; |
90 | typedef M::iterator R; |
91 | M m; |
92 | assert(DefaultOnly::count == 0); |
93 | R r = m.emplace(); |
94 | assert(r == m.begin()); |
95 | assert(m.size() == 1); |
96 | assert(m.begin()->first == 0); |
97 | assert(m.begin()->second == DefaultOnly()); |
98 | assert(DefaultOnly::count == 1); |
99 | r = m.emplace(std::piecewise_construct, std::forward_as_tuple(args: 1), |
100 | std::forward_as_tuple()); |
101 | assert(r == std::next(m.begin())); |
102 | assert(m.size() == 2); |
103 | assert(std::next(m.begin())->first == 1); |
104 | assert(std::next(m.begin())->second == DefaultOnly()); |
105 | assert(DefaultOnly::count == 2); |
106 | r = m.emplace(std::piecewise_construct, std::forward_as_tuple(args: 1), |
107 | std::forward_as_tuple()); |
108 | assert(r == std::next(m.begin(), 2)); |
109 | assert(m.size() == 3); |
110 | assert(std::next(m.begin(), 2)->first == 1); |
111 | assert(std::next(m.begin(), 2)->second == DefaultOnly()); |
112 | assert(DefaultOnly::count == 3); |
113 | } |
114 | assert(DefaultOnly::count == 0); |
115 | { |
116 | typedef std::multimap<int, Emplaceable, std::less<int>, min_allocator<std::pair<const int, Emplaceable>>> M; |
117 | typedef M::iterator R; |
118 | M m; |
119 | R r = m.emplace(std::piecewise_construct, std::forward_as_tuple(args: 2), |
120 | std::forward_as_tuple()); |
121 | assert(r == m.begin()); |
122 | assert(m.size() == 1); |
123 | assert(m.begin()->first == 2); |
124 | assert(m.begin()->second == Emplaceable()); |
125 | r = m.emplace(std::piecewise_construct, std::forward_as_tuple(args: 1), |
126 | std::forward_as_tuple(args: 2, args: 3.5)); |
127 | assert(r == m.begin()); |
128 | assert(m.size() == 2); |
129 | assert(m.begin()->first == 1); |
130 | assert(m.begin()->second == Emplaceable(2, 3.5)); |
131 | r = m.emplace(std::piecewise_construct, std::forward_as_tuple(args: 1), |
132 | std::forward_as_tuple(args: 3, args: 3.5)); |
133 | assert(r == std::next(m.begin())); |
134 | assert(m.size() == 3); |
135 | assert(r->first == 1); |
136 | assert(r->second == Emplaceable(3, 3.5)); |
137 | } |
138 | { |
139 | typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; |
140 | typedef M::iterator R; |
141 | M m; |
142 | R r = m.emplace(M::value_type(2, 3.5)); |
143 | assert(r == m.begin()); |
144 | assert(m.size() == 1); |
145 | assert(m.begin()->first == 2); |
146 | assert(m.begin()->second == 3.5); |
147 | } |
148 | |
149 | return 0; |
150 | } |
151 | |