llvm-project
160 строк · 6.2 Кб
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 map
14
15// template <class... Args>
16// iterator emplace_hint(const_iterator position, 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
26int main(int, char**)
27{
28{
29typedef std::map<int, DefaultOnly> M;
30typedef M::iterator R;
31M m;
32assert(DefaultOnly::count == 0);
33R r = m.emplace_hint(m.end());
34assert(r == m.begin());
35assert(m.size() == 1);
36assert(m.begin()->first == 0);
37assert(m.begin()->second == DefaultOnly());
38assert(DefaultOnly::count == 1);
39r = m.emplace_hint(m.end(), std::piecewise_construct,
40std::forward_as_tuple(1),
41std::forward_as_tuple());
42assert(r == std::next(m.begin()));
43assert(m.size() == 2);
44assert(std::next(m.begin())->first == 1);
45assert(std::next(m.begin())->second == DefaultOnly());
46assert(DefaultOnly::count == 2);
47r = m.emplace_hint(m.end(), std::piecewise_construct,
48std::forward_as_tuple(1),
49std::forward_as_tuple());
50assert(r == std::next(m.begin()));
51assert(m.size() == 2);
52assert(std::next(m.begin())->first == 1);
53assert(std::next(m.begin())->second == DefaultOnly());
54assert(DefaultOnly::count == 2);
55}
56assert(DefaultOnly::count == 0);
57{
58typedef std::map<int, Emplaceable> M;
59typedef M::iterator R;
60M m;
61R r = m.emplace_hint(m.end(), std::piecewise_construct,
62std::forward_as_tuple(2),
63std::forward_as_tuple());
64assert(r == m.begin());
65assert(m.size() == 1);
66assert(m.begin()->first == 2);
67assert(m.begin()->second == Emplaceable());
68r = m.emplace_hint(m.end(), std::piecewise_construct,
69std::forward_as_tuple(1),
70std::forward_as_tuple(2, 3.5));
71assert(r == m.begin());
72assert(m.size() == 2);
73assert(m.begin()->first == 1);
74assert(m.begin()->second == Emplaceable(2, 3.5));
75r = m.emplace_hint(m.end(), std::piecewise_construct,
76std::forward_as_tuple(1),
77std::forward_as_tuple(2, 3.5));
78assert(r == m.begin());
79assert(m.size() == 2);
80assert(m.begin()->first == 1);
81assert(m.begin()->second == Emplaceable(2, 3.5));
82}
83{
84typedef std::map<int, double> M;
85typedef M::iterator R;
86M m;
87R r = m.emplace_hint(m.end(), M::value_type(2, 3.5));
88assert(r == m.begin());
89assert(m.size() == 1);
90assert(m.begin()->first == 2);
91assert(m.begin()->second == 3.5);
92}
93{
94typedef std::map<int, DefaultOnly, std::less<int>, min_allocator<std::pair<const int, DefaultOnly>>> M;
95typedef M::iterator R;
96M m;
97assert(DefaultOnly::count == 0);
98R r = m.emplace_hint(m.end());
99assert(r == m.begin());
100assert(m.size() == 1);
101assert(m.begin()->first == 0);
102assert(m.begin()->second == DefaultOnly());
103assert(DefaultOnly::count == 1);
104r = m.emplace_hint(m.end(), std::piecewise_construct,
105std::forward_as_tuple(1),
106std::forward_as_tuple());
107assert(r == std::next(m.begin()));
108assert(m.size() == 2);
109assert(std::next(m.begin())->first == 1);
110assert(std::next(m.begin())->second == DefaultOnly());
111assert(DefaultOnly::count == 2);
112r = m.emplace_hint(m.end(), std::piecewise_construct,
113std::forward_as_tuple(1),
114std::forward_as_tuple());
115assert(r == std::next(m.begin()));
116assert(m.size() == 2);
117assert(std::next(m.begin())->first == 1);
118assert(std::next(m.begin())->second == DefaultOnly());
119assert(DefaultOnly::count == 2);
120}
121assert(DefaultOnly::count == 0);
122{
123typedef std::map<int, Emplaceable, std::less<int>, min_allocator<std::pair<const int, Emplaceable>>> M;
124typedef M::iterator R;
125M m;
126R r = m.emplace_hint(m.end(), std::piecewise_construct,
127std::forward_as_tuple(2),
128std::forward_as_tuple());
129assert(r == m.begin());
130assert(m.size() == 1);
131assert(m.begin()->first == 2);
132assert(m.begin()->second == Emplaceable());
133r = m.emplace_hint(m.end(), std::piecewise_construct,
134std::forward_as_tuple(1),
135std::forward_as_tuple(2, 3.5));
136assert(r == m.begin());
137assert(m.size() == 2);
138assert(m.begin()->first == 1);
139assert(m.begin()->second == Emplaceable(2, 3.5));
140r = m.emplace_hint(m.end(), std::piecewise_construct,
141std::forward_as_tuple(1),
142std::forward_as_tuple(2, 3.5));
143assert(r == m.begin());
144assert(m.size() == 2);
145assert(m.begin()->first == 1);
146assert(m.begin()->second == Emplaceable(2, 3.5));
147}
148{
149typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
150typedef M::iterator R;
151M m;
152R r = m.emplace_hint(m.end(), M::value_type(2, 3.5));
153assert(r == m.begin());
154assert(m.size() == 1);
155assert(m.begin()->first == 2);
156assert(m.begin()->second == 3.5);
157}
158
159return 0;
160}
161