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_hint(const_iterator position, 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_hint(m.cend());
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_hint(m.cend(), std::piecewise_construct,
40 std::forward_as_tuple(1),
41 std::forward_as_tuple());
42 assert(r == next(m.begin()));
43 assert(m.size() == 2);
44 assert(next(m.begin())->first == 1);
45 assert(next(m.begin())->second == DefaultOnly());
46 assert(DefaultOnly::count == 2);
47 r = m.emplace_hint(m.cend(), std::piecewise_construct,
48 std::forward_as_tuple(1),
49 std::forward_as_tuple());
50 assert(r == next(m.begin(), 2));
51 assert(m.size() == 3);
52 assert(next(m.begin(), 2)->first == 1);
53 assert(next(m.begin(), 2)->second == DefaultOnly());
54 assert(DefaultOnly::count == 3);
55 }
56 assert(DefaultOnly::count == 0);
57 {
58 typedef std::multimap<int, Emplaceable> M;
59 typedef M::iterator R;
60 M m;
61 R r = m.emplace_hint(m.cend(), std::piecewise_construct,
62 std::forward_as_tuple(2),
63 std::forward_as_tuple());
64 assert(r == m.begin());
65 assert(m.size() == 1);
66 assert(m.begin()->first == 2);
67 assert(m.begin()->second == Emplaceable());
68 r = m.emplace_hint(m.cbegin(), std::piecewise_construct,
69 std::forward_as_tuple(1),
70 std::forward_as_tuple(2, 3.5));
71 assert(r == m.begin());
72 assert(m.size() == 2);
73 assert(m.begin()->first == 1);
74 assert(m.begin()->second == Emplaceable(2, 3.5));
75 r = m.emplace_hint(m.cbegin(), std::piecewise_construct,
76 std::forward_as_tuple(1),
77 std::forward_as_tuple(3, 3.5));
78 assert(r == m.begin());
79 assert(m.size() == 3);
80 assert(r->first == 1);
81 assert(r->second == Emplaceable(3, 3.5));
82 }
83 {
84 typedef std::multimap<int, double> M;
85 typedef M::iterator R;
86 M m;
87 R r = m.emplace_hint(m.cend(), M::value_type(2, 3.5));
88 assert(r == m.begin());
89 assert(m.size() == 1);
90 assert(m.begin()->first == 2);
91 assert(m.begin()->second == 3.5);
92 }
93 {
94 typedef std::multimap<int, DefaultOnly, std::less<int>, min_allocator<std::pair<const int, DefaultOnly>>> M;
95 typedef M::iterator R;
96 M m;
97 assert(DefaultOnly::count == 0);
98 R r = m.emplace_hint(m.cend());
99 assert(r == m.begin());
100 assert(m.size() == 1);
101 assert(m.begin()->first == 0);
102 assert(m.begin()->second == DefaultOnly());
103 assert(DefaultOnly::count == 1);
104 r = m.emplace_hint(m.cend(), std::piecewise_construct,
105 std::forward_as_tuple(1),
106 std::forward_as_tuple());
107 assert(r == next(m.begin()));
108 assert(m.size() == 2);
109 assert(next(m.begin())->first == 1);
110 assert(next(m.begin())->second == DefaultOnly());
111 assert(DefaultOnly::count == 2);
112 r = m.emplace_hint(m.cend(), std::piecewise_construct,
113 std::forward_as_tuple(1),
114 std::forward_as_tuple());
115 assert(r == next(m.begin(), 2));
116 assert(m.size() == 3);
117 assert(next(m.begin(), 2)->first == 1);
118 assert(next(m.begin(), 2)->second == DefaultOnly());
119 assert(DefaultOnly::count == 3);
120 }
121 assert(DefaultOnly::count == 0);
122 {
123 typedef std::multimap<int, Emplaceable, std::less<int>, min_allocator<std::pair<const int, Emplaceable>>> M;
124 typedef M::iterator R;
125 M m;
126 R r = m.emplace_hint(m.cend(), std::piecewise_construct,
127 std::forward_as_tuple(2),
128 std::forward_as_tuple());
129 assert(r == m.begin());
130 assert(m.size() == 1);
131 assert(m.begin()->first == 2);
132 assert(m.begin()->second == Emplaceable());
133 r = m.emplace_hint(m.cbegin(), std::piecewise_construct,
134 std::forward_as_tuple(1),
135 std::forward_as_tuple(2, 3.5));
136 assert(r == m.begin());
137 assert(m.size() == 2);
138 assert(m.begin()->first == 1);
139 assert(m.begin()->second == Emplaceable(2, 3.5));
140 r = m.emplace_hint(m.cbegin(), std::piecewise_construct,
141 std::forward_as_tuple(1),
142 std::forward_as_tuple(3, 3.5));
143 assert(r == m.begin());
144 assert(m.size() == 3);
145 assert(r->first == 1);
146 assert(r->second == Emplaceable(3, 3.5));
147 }
148 {
149 typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
150 typedef M::iterator R;
151 M m;
152 R r = m.emplace_hint(m.cend(), M::value_type(2, 3.5));
153 assert(r == m.begin());
154 assert(m.size() == 1);
155 assert(m.begin()->first == 2);
156 assert(m.begin()->second == 3.5);
157 }
158 }
159