1
//===----------------------------------------------------------------------===//
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
7
//===----------------------------------------------------------------------===//
15
// template <class... Args>
16
// iterator emplace_hint(const_iterator position, Args&&... args);
21
#include "test_macros.h"
22
#include "../../../Emplaceable.h"
23
#include "DefaultOnly.h"
24
#include "min_allocator.h"
29
typedef std::multimap<int, DefaultOnly> M;
30
typedef M::iterator R;
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 == std::next(m.begin()));
43
assert(m.size() == 2);
44
assert(std::next(m.begin())->first == 1);
45
assert(std::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 == std::next(m.begin(), 2));
51
assert(m.size() == 3);
52
assert(std::next(m.begin(), 2)->first == 1);
53
assert(std::next(m.begin(), 2)->second == DefaultOnly());
54
assert(DefaultOnly::count == 3);
56
assert(DefaultOnly::count == 0);
58
typedef std::multimap<int, Emplaceable> M;
59
typedef M::iterator R;
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));
84
typedef std::multimap<int, double> M;
85
typedef M::iterator R;
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);
94
typedef std::multimap<int, DefaultOnly, std::less<int>, min_allocator<std::pair<const int, DefaultOnly>>> M;
95
typedef M::iterator R;
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 == std::next(m.begin()));
108
assert(m.size() == 2);
109
assert(std::next(m.begin())->first == 1);
110
assert(std::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 == std::next(m.begin(), 2));
116
assert(m.size() == 3);
117
assert(std::next(m.begin(), 2)->first == 1);
118
assert(std::next(m.begin(), 2)->second == DefaultOnly());
119
assert(DefaultOnly::count == 3);
121
assert(DefaultOnly::count == 0);
123
typedef std::multimap<int, Emplaceable, std::less<int>, min_allocator<std::pair<const int, Emplaceable>>> M;
124
typedef M::iterator R;
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));
149
typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
150
typedef M::iterator R;
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);