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 // pair<iterator, bool> emplace(Args&&... args);
22 #include "test_macros.h"
23 #include "../../../Emplaceable.h"
24 #include "DefaultOnly.h"
25 #include "min_allocator.h"
30 typedef std::map
<int, DefaultOnly
> M
;
31 typedef std::pair
<M::iterator
, bool> R
;
33 assert(DefaultOnly::count
== 0);
36 assert(r
.first
== m
.begin());
37 assert(m
.size() == 1);
38 assert(m
.begin()->first
== 0);
39 assert(m
.begin()->second
== DefaultOnly());
40 assert(DefaultOnly::count
== 1);
41 r
= m
.emplace(std::piecewise_construct
, std::forward_as_tuple(1),
42 std::forward_as_tuple());
44 assert(r
.first
== std::next(m
.begin()));
45 assert(m
.size() == 2);
46 assert(std::next(m
.begin())->first
== 1);
47 assert(std::next(m
.begin())->second
== DefaultOnly());
48 assert(DefaultOnly::count
== 2);
49 r
= m
.emplace(std::piecewise_construct
, std::forward_as_tuple(1),
50 std::forward_as_tuple());
52 assert(r
.first
== std::next(m
.begin()));
53 assert(m
.size() == 2);
54 assert(std::next(m
.begin())->first
== 1);
55 assert(std::next(m
.begin())->second
== DefaultOnly());
56 assert(DefaultOnly::count
== 2);
58 assert(DefaultOnly::count
== 0);
60 typedef std::map
<int, Emplaceable
> M
;
61 typedef std::pair
<M::iterator
, bool> R
;
63 R r
= m
.emplace(std::piecewise_construct
, std::forward_as_tuple(2),
64 std::forward_as_tuple());
66 assert(r
.first
== m
.begin());
67 assert(m
.size() == 1);
68 assert(m
.begin()->first
== 2);
69 assert(m
.begin()->second
== Emplaceable());
70 r
= m
.emplace(std::piecewise_construct
, std::forward_as_tuple(1),
71 std::forward_as_tuple(2, 3.5));
73 assert(r
.first
== m
.begin());
74 assert(m
.size() == 2);
75 assert(m
.begin()->first
== 1);
76 assert(m
.begin()->second
== Emplaceable(2, 3.5));
77 r
= m
.emplace(std::piecewise_construct
, std::forward_as_tuple(1),
78 std::forward_as_tuple(2, 3.5));
80 assert(r
.first
== m
.begin());
81 assert(m
.size() == 2);
82 assert(m
.begin()->first
== 1);
83 assert(m
.begin()->second
== Emplaceable(2, 3.5));
86 typedef std::map
<int, double> M
;
87 typedef std::pair
<M::iterator
, bool> R
;
89 R r
= m
.emplace(M::value_type(2, 3.5));
91 assert(r
.first
== m
.begin());
92 assert(m
.size() == 1);
93 assert(m
.begin()->first
== 2);
94 assert(m
.begin()->second
== 3.5);
97 typedef std::map
<int, DefaultOnly
, std::less
<int>, min_allocator
<std::pair
<const int, DefaultOnly
>>> M
;
98 typedef std::pair
<M::iterator
, bool> R
;
100 assert(DefaultOnly::count
== 0);
103 assert(r
.first
== m
.begin());
104 assert(m
.size() == 1);
105 assert(m
.begin()->first
== 0);
106 assert(m
.begin()->second
== DefaultOnly());
107 assert(DefaultOnly::count
== 1);
108 r
= m
.emplace(std::piecewise_construct
, std::forward_as_tuple(1),
109 std::forward_as_tuple());
111 assert(r
.first
== std::next(m
.begin()));
112 assert(m
.size() == 2);
113 assert(std::next(m
.begin())->first
== 1);
114 assert(std::next(m
.begin())->second
== DefaultOnly());
115 assert(DefaultOnly::count
== 2);
116 r
= m
.emplace(std::piecewise_construct
, std::forward_as_tuple(1),
117 std::forward_as_tuple());
119 assert(r
.first
== std::next(m
.begin()));
120 assert(m
.size() == 2);
121 assert(std::next(m
.begin())->first
== 1);
122 assert(std::next(m
.begin())->second
== DefaultOnly());
123 assert(DefaultOnly::count
== 2);
125 assert(DefaultOnly::count
== 0);
127 typedef std::map
<int, Emplaceable
, std::less
<int>, min_allocator
<std::pair
<const int, Emplaceable
>>> M
;
128 typedef std::pair
<M::iterator
, bool> R
;
130 R r
= m
.emplace(std::piecewise_construct
, std::forward_as_tuple(2),
131 std::forward_as_tuple());
133 assert(r
.first
== m
.begin());
134 assert(m
.size() == 1);
135 assert(m
.begin()->first
== 2);
136 assert(m
.begin()->second
== Emplaceable());
137 r
= m
.emplace(std::piecewise_construct
, std::forward_as_tuple(1),
138 std::forward_as_tuple(2, 3.5));
140 assert(r
.first
== m
.begin());
141 assert(m
.size() == 2);
142 assert(m
.begin()->first
== 1);
143 assert(m
.begin()->second
== Emplaceable(2, 3.5));
144 r
= m
.emplace(std::piecewise_construct
, std::forward_as_tuple(1),
145 std::forward_as_tuple(2, 3.5));
147 assert(r
.first
== m
.begin());
148 assert(m
.size() == 2);
149 assert(m
.begin()->first
== 1);
150 assert(m
.begin()->second
== Emplaceable(2, 3.5));
153 typedef std::map
<int, double, std::less
<int>, min_allocator
<std::pair
<const int, double>>> M
;
154 typedef std::pair
<M::iterator
, bool> R
;
156 R r
= m
.emplace(M::value_type(2, 3.5));
158 assert(r
.first
== m
.begin());
159 assert(m
.size() == 1);
160 assert(m
.begin()->first
== 2);
161 assert(m
.begin()->second
== 3.5);