1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // UNSUPPORTED: c++98, c++03
11
12 // <map>
13
14 // class multimap
15
16 // template <class... Args>
17 // iterator emplace(Args&&... args);
18
19 #include <map>
20 #include <cassert>
21
22 #include "../../../Emplaceable.h"
23 #include "DefaultOnly.h"
24 #include "min_allocator.h"
25
main()26 int main()
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(1),
40 std::forward_as_tuple());
41 assert(r == next(m.begin()));
42 assert(m.size() == 2);
43 assert(next(m.begin())->first == 1);
44 assert(next(m.begin())->second == DefaultOnly());
45 assert(DefaultOnly::count == 2);
46 r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1),
47 std::forward_as_tuple());
48 assert(r == next(m.begin(), 2));
49 assert(m.size() == 3);
50 assert(next(m.begin(), 2)->first == 1);
51 assert(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(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(1),
66 std::forward_as_tuple(2, 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(1),
72 std::forward_as_tuple(3, 3.5));
73 assert(r == 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(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(1),
100 std::forward_as_tuple());
101 assert(r == next(m.begin()));
102 assert(m.size() == 2);
103 assert(next(m.begin())->first == 1);
104 assert(next(m.begin())->second == DefaultOnly());
105 assert(DefaultOnly::count == 2);
106 r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1),
107 std::forward_as_tuple());
108 assert(r == next(m.begin(), 2));
109 assert(m.size() == 3);
110 assert(next(m.begin(), 2)->first == 1);
111 assert(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(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(1),
126 std::forward_as_tuple(2, 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(1),
132 std::forward_as_tuple(3, 3.5));
133 assert(r == 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