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
20 #include "test_macros.h"
21 #include "../../../Emplaceable.h"
22 #include "min_allocator.h"
23 #include "test_allocator.h"
27 make(int size
, int start
= 0 )
29 const int b
= 4096 / sizeof(int);
33 init
= (start
+1) / b
+ ((start
+1) % b
!= 0);
38 for (int i
= 0; i
< init
-start
; ++i
)
40 for (int i
= 0; i
< size
; ++i
)
41 c
.push_back(Emplaceable());
42 for (int i
= 0; i
< start
; ++i
)
51 typedef typename
C::iterator I
;
52 std::size_t c1_osize
= c1
.size();
54 typedef typename
C::reference Ref
;
55 Ref res_ref
= c1
.emplace_front(Emplaceable(1, 2.5));
57 c1
.emplace_front(Emplaceable(1, 2.5));
59 assert(c1
.size() == c1_osize
+ 1);
60 assert(distance(c1
.begin(), c1
.end())
61 == static_cast<std::ptrdiff_t>(c1
.size()));
63 assert(*i
== Emplaceable(1, 2.5));
65 assert(&res_ref
== &(*i
));
71 testN(int start
, int N
)
73 C c1
= make
<C
>(N
, start
);
81 int rng
[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
82 const int N
= sizeof(rng
)/sizeof(rng
[0]);
83 for (int i
= 0; i
< N
; ++i
)
84 for (int j
= 0; j
< N
; ++j
)
85 testN
<std::deque
<Emplaceable
> >(rng
[i
], rng
[j
]);
88 int rng
[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
89 const int N
= sizeof(rng
)/sizeof(rng
[0]);
90 for (int i
= 0; i
< N
; ++i
)
91 for (int j
= 0; j
< N
; ++j
)
92 testN
<std::deque
<Emplaceable
, min_allocator
<Emplaceable
>> >(rng
[i
], rng
[j
]);
95 std::deque
<Tag_X
, TaggingAllocator
<Tag_X
>> c
;
97 assert(c
.size() == 1);
98 c
.emplace_front(1, 2, 3);
99 assert(c
.size() == 2);
101 assert(c
.size() == 3);
102 c
.emplace_front(1, 2, 3);
103 assert(c
.size() == 4);