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 //===----------------------------------------------------------------------===//
13 // template <class... Args> iterator emplace(const_iterator pos, Args&&... args);
18 #include "test_macros.h"
19 #include "test_allocator.h"
20 #include "min_allocator.h"
21 #include "asan_testing.h"
29 A
& operator=(const A
&);
51 int geti() const {return i_
;}
52 double getd() const {return d_
;}
59 std::vector
<A
>::iterator i
= c
.emplace(c
.cbegin(), 2, 3.5);
60 assert(i
== c
.begin());
61 assert(c
.size() == 1);
62 assert(c
.front().geti() == 2);
63 assert(c
.front().getd() == 3.5);
64 assert(is_contiguous_container_asan_correct(c
));
65 i
= c
.emplace(c
.cend(), 3, 4.5);
66 assert(i
== c
.end()-1);
67 assert(c
.size() == 2);
68 assert(c
.front().geti() == 2);
69 assert(c
.front().getd() == 3.5);
70 assert(c
.back().geti() == 3);
71 assert(c
.back().getd() == 4.5);
72 assert(is_contiguous_container_asan_correct(c
));
73 i
= c
.emplace(c
.cbegin()+1, 4, 6.5);
74 assert(i
== c
.begin()+1);
75 assert(c
.size() == 3);
76 assert(c
.front().geti() == 2);
77 assert(c
.front().getd() == 3.5);
78 assert(c
[1].geti() == 4);
79 assert(c
[1].getd() == 6.5);
80 assert(c
.back().geti() == 3);
81 assert(c
.back().getd() == 4.5);
82 assert(is_contiguous_container_asan_correct(c
));
85 std::vector
<A
, limited_allocator
<A
, 7> > c
;
86 std::vector
<A
, limited_allocator
<A
, 7> >::iterator i
= c
.emplace(c
.cbegin(), 2, 3.5);
87 assert(i
== c
.begin());
88 assert(c
.size() == 1);
89 assert(c
.front().geti() == 2);
90 assert(c
.front().getd() == 3.5);
91 assert(is_contiguous_container_asan_correct(c
));
92 i
= c
.emplace(c
.cend(), 3, 4.5);
93 assert(i
== c
.end()-1);
94 assert(c
.size() == 2);
95 assert(c
.front().geti() == 2);
96 assert(c
.front().getd() == 3.5);
97 assert(c
.back().geti() == 3);
98 assert(c
.back().getd() == 4.5);
99 assert(is_contiguous_container_asan_correct(c
));
100 i
= c
.emplace(c
.cbegin()+1, 4, 6.5);
101 assert(i
== c
.begin()+1);
102 assert(c
.size() == 3);
103 assert(c
.front().geti() == 2);
104 assert(c
.front().getd() == 3.5);
105 assert(c
[1].geti() == 4);
106 assert(c
[1].getd() == 6.5);
107 assert(c
.back().geti() == 3);
108 assert(c
.back().getd() == 4.5);
109 assert(is_contiguous_container_asan_correct(c
));
112 std::vector
<A
, min_allocator
<A
>> c
;
113 std::vector
<A
, min_allocator
<A
>>::iterator i
= c
.emplace(c
.cbegin(), 2, 3.5);
114 assert(i
== c
.begin());
115 assert(c
.size() == 1);
116 assert(c
.front().geti() == 2);
117 assert(c
.front().getd() == 3.5);
118 i
= c
.emplace(c
.cend(), 3, 4.5);
119 assert(i
== c
.end()-1);
120 assert(c
.size() == 2);
121 assert(c
.front().geti() == 2);
122 assert(c
.front().getd() == 3.5);
123 assert(c
.back().geti() == 3);
124 assert(c
.back().getd() == 4.5);
125 i
= c
.emplace(c
.cbegin()+1, 4, 6.5);
126 assert(i
== c
.begin()+1);
127 assert(c
.size() == 3);
128 assert(c
.front().geti() == 2);
129 assert(c
.front().getd() == 3.5);
130 assert(c
[1].geti() == 4);
131 assert(c
[1].getd() == 6.5);
132 assert(c
.back().geti() == 3);
133 assert(c
.back().getd() == 4.5);