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> reference emplace_front(Args&&... args);
14 // return type is 'reference' in C++17; 'void' before
16 #include "asan_testing.h"
21 #include "test_macros.h"
22 #include "../../../Emplaceable.h"
23 #include "min_allocator.h"
24 #include "test_allocator.h"
28 make(int size
, int start
= 0 )
30 const int b
= 4096 / sizeof(int);
34 init
= (start
+1) / b
+ ((start
+1) % b
!= 0);
39 for (int i
= 0; i
< init
-start
; ++i
)
41 for (int i
= 0; i
< size
; ++i
)
42 c
.push_back(Emplaceable());
43 for (int i
= 0; i
< start
; ++i
)
52 typedef typename
C::iterator I
;
53 std::size_t c1_osize
= c1
.size();
55 typedef typename
C::reference Ref
;
56 Ref res_ref
= c1
.emplace_front(Emplaceable(1, 2.5));
58 c1
.emplace_front(Emplaceable(1, 2.5));
60 assert(c1
.size() == c1_osize
+ 1);
61 assert(std::distance(c1
.begin(), c1
.end())
62 == static_cast<std::ptrdiff_t>(c1
.size()));
64 assert(*i
== Emplaceable(1, 2.5));
65 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c1
));
67 assert(&res_ref
== &(*i
));
73 testN(int start
, int N
)
75 C c1
= make
<C
>(N
, start
);
83 int rng
[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
84 const int N
= sizeof(rng
)/sizeof(rng
[0]);
85 for (int i
= 0; i
< N
; ++i
)
86 for (int j
= 0; j
< N
; ++j
)
87 testN
<std::deque
<Emplaceable
> >(rng
[i
], rng
[j
]);
90 int rng
[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
91 const int N
= sizeof(rng
)/sizeof(rng
[0]);
92 for (int i
= 0; i
< N
; ++i
)
93 for (int j
= 0; j
< N
; ++j
)
94 testN
<std::deque
<Emplaceable
, min_allocator
<Emplaceable
>> >(rng
[i
], rng
[j
]);
97 std::deque
<Tag_X
, TaggingAllocator
<Tag_X
>> c
;
99 assert(c
.size() == 1);
100 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c
));
101 c
.emplace_front(1, 2, 3);
102 assert(c
.size() == 2);
103 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c
));
105 assert(c
.size() == 3);
106 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c
));
107 c
.emplace_front(1, 2, 3);
108 assert(c
.size() == 4);
109 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c
));