xref: /llvm-project/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back_rvalue.pass.cpp (revision 10ec9276d40024c23a481e6671dad1521151dd85)
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03
10 
11 // <deque>
12 
13 // void push_back(value_type&& v);
14 // void pop_back();
15 // void pop_front();
16 
17 #include "asan_testing.h"
18 #include <deque>
19 #include <cassert>
20 
21 #include "test_macros.h"
22 #include "MoveOnly.h"
23 #include "min_allocator.h"
24 
25 
26 template <class C>
27 C
make(int size,int start=0)28 make(int size, int start = 0 )
29 {
30     const int b = 4096 / sizeof(int);
31     int init = 0;
32     if (start > 0)
33     {
34         init = (start+1) / b + ((start+1) % b != 0);
35         init *= b;
36         --init;
37     }
38     C c(init);
39     for (int i = 0; i < init-start; ++i)
40         c.pop_back();
41     for (int i = 0; i < size; ++i)
42         c.push_back(MoveOnly(i));
43     for (int i = 0; i < start; ++i)
44         c.pop_front();
45     return c;
46 }
47 
48 template <class C>
test(int size)49 void test(int size)
50 {
51     int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049};
52     const int N = sizeof(rng)/sizeof(rng[0]);
53     for (int j = 0; j < N; ++j)
54     {
55         C c = make<C>(size, rng[j]);
56         typename C::const_iterator it = c.begin();
57         LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c));
58         for (int i = 0; i < size; ++i, (void) ++it)
59             assert(*it == MoveOnly(i));
60     }
61 }
62 
63 
main(int,char **)64 int main(int, char**)
65 {
66     {
67     int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049, 4094, 4095, 4096};
68     const int N = sizeof(rng)/sizeof(rng[0]);
69     for (int j = 0; j < N; ++j)
70         test<std::deque<MoveOnly> >(rng[j]);
71     }
72     {
73     int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049, 4094, 4095, 4096};
74     const int N = sizeof(rng)/sizeof(rng[0]);
75     for (int j = 0; j < N; ++j)
76         test<std::deque<MoveOnly, min_allocator<MoveOnly>> >(rng[j]);
77     }
78     {
79     int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049, 4094, 4095, 4096};
80     const int N = sizeof(rng)/sizeof(rng[0]);
81     for (int j = 0; j < N; ++j)
82         test<std::deque<MoveOnly, safe_allocator<MoveOnly>> >(rng[j]);
83     }
84 
85   return 0;
86 }
87