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(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);
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(std::piecewise_construct
, std::forward_as_tuple(1),
40 std::forward_as_tuple());
41 assert(r
== std::next(m
.begin()));
42 assert(m
.size() == 2);
43 assert(std::next(m
.begin())->first
== 1);
44 assert(std::next(m
.begin())->second
== DefaultOnly());
45 assert(DefaultOnly::count
== 2);
46 r
= m
.emplace(std::piecewise_construct
, std::forward_as_tuple(1),
47 std::forward_as_tuple());
48 assert(r
== std::next(m
.begin(), 2));
49 assert(m
.size() == 3);
50 assert(std::next(m
.begin(), 2)->first
== 1);
51 assert(std::next(m
.begin(), 2)->second
== DefaultOnly());
52 assert(DefaultOnly::count
== 3);
54 assert(DefaultOnly::count
== 0);
56 typedef std::multimap
<int, Emplaceable
> M
;
57 typedef M::iterator R
;
59 R r
= m
.emplace(std::piecewise_construct
, std::forward_as_tuple(2),
60 std::forward_as_tuple());
61 assert(r
== m
.begin());
62 assert(m
.size() == 1);
63 assert(m
.begin()->first
== 2);
64 assert(m
.begin()->second
== Emplaceable());
65 r
= m
.emplace(std::piecewise_construct
, std::forward_as_tuple(1),
66 std::forward_as_tuple(2, 3.5));
67 assert(r
== m
.begin());
68 assert(m
.size() == 2);
69 assert(m
.begin()->first
== 1);
70 assert(m
.begin()->second
== Emplaceable(2, 3.5));
71 r
= m
.emplace(std::piecewise_construct
, std::forward_as_tuple(1),
72 std::forward_as_tuple(3, 3.5));
73 assert(r
== std::next(m
.begin()));
74 assert(m
.size() == 3);
75 assert(r
->first
== 1);
76 assert(r
->second
== Emplaceable(3, 3.5));
79 typedef std::multimap
<int, double> M
;
80 typedef M::iterator R
;
82 R r
= m
.emplace(M::value_type(2, 3.5));
83 assert(r
== m
.begin());
84 assert(m
.size() == 1);
85 assert(m
.begin()->first
== 2);
86 assert(m
.begin()->second
== 3.5);
89 typedef std::multimap
<int, DefaultOnly
, std::less
<int>, min_allocator
<std::pair
<const int, DefaultOnly
>>> M
;
90 typedef M::iterator R
;
92 assert(DefaultOnly::count
== 0);
94 assert(r
== m
.begin());
95 assert(m
.size() == 1);
96 assert(m
.begin()->first
== 0);
97 assert(m
.begin()->second
== DefaultOnly());
98 assert(DefaultOnly::count
== 1);
99 r
= m
.emplace(std::piecewise_construct
, std::forward_as_tuple(1),
100 std::forward_as_tuple());
101 assert(r
== std::next(m
.begin()));
102 assert(m
.size() == 2);
103 assert(std::next(m
.begin())->first
== 1);
104 assert(std::next(m
.begin())->second
== DefaultOnly());
105 assert(DefaultOnly::count
== 2);
106 r
= m
.emplace(std::piecewise_construct
, std::forward_as_tuple(1),
107 std::forward_as_tuple());
108 assert(r
== std::next(m
.begin(), 2));
109 assert(m
.size() == 3);
110 assert(std::next(m
.begin(), 2)->first
== 1);
111 assert(std::next(m
.begin(), 2)->second
== DefaultOnly());
112 assert(DefaultOnly::count
== 3);
114 assert(DefaultOnly::count
== 0);
116 typedef std::multimap
<int, Emplaceable
, std::less
<int>, min_allocator
<std::pair
<const int, Emplaceable
>>> M
;
117 typedef M::iterator R
;
119 R r
= m
.emplace(std::piecewise_construct
, std::forward_as_tuple(2),
120 std::forward_as_tuple());
121 assert(r
== m
.begin());
122 assert(m
.size() == 1);
123 assert(m
.begin()->first
== 2);
124 assert(m
.begin()->second
== Emplaceable());
125 r
= m
.emplace(std::piecewise_construct
, std::forward_as_tuple(1),
126 std::forward_as_tuple(2, 3.5));
127 assert(r
== m
.begin());
128 assert(m
.size() == 2);
129 assert(m
.begin()->first
== 1);
130 assert(m
.begin()->second
== Emplaceable(2, 3.5));
131 r
= m
.emplace(std::piecewise_construct
, std::forward_as_tuple(1),
132 std::forward_as_tuple(3, 3.5));
133 assert(r
== std::next(m
.begin()));
134 assert(m
.size() == 3);
135 assert(r
->first
== 1);
136 assert(r
->second
== Emplaceable(3, 3.5));
139 typedef std::multimap
<int, double, std::less
<int>, min_allocator
<std::pair
<const int, double>>> M
;
140 typedef M::iterator R
;
142 R r
= m
.emplace(M::value_type(2, 3.5));
143 assert(r
== m
.begin());
144 assert(m
.size() == 1);
145 assert(m
.begin()->first
== 2);
146 assert(m
.begin()->second
== 3.5);