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 // <map>
11
12 // class map
13
14 // template <class... Args>
15 // iterator emplace_hint(const_iterator position, Args&&... args);
16
17 #include <map>
18 #include <cassert>
19
20 #include "../../../Emplaceable.h"
21 #include "DefaultOnly.h"
22 #include "min_allocator.h"
23
main()24 int main()
25 {
26 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
27 {
28 typedef std::map<int, DefaultOnly> M;
29 typedef M::iterator R;
30 M m;
31 assert(DefaultOnly::count == 0);
32 R r = m.emplace_hint(m.end());
33 assert(r == m.begin());
34 assert(m.size() == 1);
35 assert(m.begin()->first == 0);
36 assert(m.begin()->second == DefaultOnly());
37 assert(DefaultOnly::count == 1);
38 r = m.emplace_hint(m.end(), std::piecewise_construct,
39 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_hint(m.end(), std::piecewise_construct,
47 std::forward_as_tuple(1),
48 std::forward_as_tuple());
49 assert(r == next(m.begin()));
50 assert(m.size() == 2);
51 assert(next(m.begin())->first == 1);
52 assert(next(m.begin())->second == DefaultOnly());
53 assert(DefaultOnly::count == 2);
54 }
55 assert(DefaultOnly::count == 0);
56 {
57 typedef std::map<int, Emplaceable> M;
58 typedef M::iterator R;
59 M m;
60 R r = m.emplace_hint(m.end(), std::piecewise_construct,
61 std::forward_as_tuple(2),
62 std::forward_as_tuple());
63 assert(r == m.begin());
64 assert(m.size() == 1);
65 assert(m.begin()->first == 2);
66 assert(m.begin()->second == Emplaceable());
67 r = m.emplace_hint(m.end(), std::piecewise_construct,
68 std::forward_as_tuple(1),
69 std::forward_as_tuple(2, 3.5));
70 assert(r == m.begin());
71 assert(m.size() == 2);
72 assert(m.begin()->first == 1);
73 assert(m.begin()->second == Emplaceable(2, 3.5));
74 r = m.emplace_hint(m.end(), std::piecewise_construct,
75 std::forward_as_tuple(1),
76 std::forward_as_tuple(2, 3.5));
77 assert(r == m.begin());
78 assert(m.size() == 2);
79 assert(m.begin()->first == 1);
80 assert(m.begin()->second == Emplaceable(2, 3.5));
81 }
82 {
83 typedef std::map<int, double> M;
84 typedef M::iterator R;
85 M m;
86 R r = m.emplace_hint(m.end(), M::value_type(2, 3.5));
87 assert(r == m.begin());
88 assert(m.size() == 1);
89 assert(m.begin()->first == 2);
90 assert(m.begin()->second == 3.5);
91 }
92 #if __cplusplus >= 201103L
93 {
94 typedef std::map<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.end());
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.end(), 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.end(), std::piecewise_construct,
113 std::forward_as_tuple(1),
114 std::forward_as_tuple());
115 assert(r == next(m.begin()));
116 assert(m.size() == 2);
117 assert(next(m.begin())->first == 1);
118 assert(next(m.begin())->second == DefaultOnly());
119 assert(DefaultOnly::count == 2);
120 }
121 assert(DefaultOnly::count == 0);
122 {
123 typedef std::map<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.end(), 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.end(), 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.end(), std::piecewise_construct,
141 std::forward_as_tuple(1),
142 std::forward_as_tuple(2, 3.5));
143 assert(r == m.begin());
144 assert(m.size() == 2);
145 assert(m.begin()->first == 1);
146 assert(m.begin()->second == Emplaceable(2, 3.5));
147 }
148 {
149 typedef std::map<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.end(), 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 #endif
159 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
160 }
161