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 <deque>
18 #include <cassert>
19
20 #include "test_macros.h"
21 #include "MoveOnly.h"
22 #include "min_allocator.h"
23
24
25 template <class C>
26 C
make(int size,int start=0)27 make(int size, int start = 0 )
28 {
29 const int b = 4096 / sizeof(int);
30 int init = 0;
31 if (start > 0)
32 {
33 init = (start+1) / b + ((start+1) % b != 0);
34 init *= b;
35 --init;
36 }
37 C c(init);
38 for (int i = 0; i < init-start; ++i)
39 c.pop_back();
40 for (int i = 0; i < size; ++i)
41 c.push_back(MoveOnly(i));
42 for (int i = 0; i < start; ++i)
43 c.pop_front();
44 return c;
45 }
46
47 template <class C>
test(int size)48 void test(int size)
49 {
50 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049};
51 const int N = sizeof(rng)/sizeof(rng[0]);
52 for (int j = 0; j < N; ++j)
53 {
54 C c = make<C>(size, rng[j]);
55 typename C::const_iterator it = c.begin();
56 for (int i = 0; i < size; ++i, (void) ++it)
57 assert(*it == MoveOnly(i));
58 }
59 }
60
61
main(int,char **)62 int main(int, char**)
63 {
64 {
65 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049, 4094, 4095, 4096};
66 const int N = sizeof(rng)/sizeof(rng[0]);
67 for (int j = 0; j < N; ++j)
68 test<std::deque<MoveOnly> >(rng[j]);
69 }
70 {
71 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049, 4094, 4095, 4096};
72 const int N = sizeof(rng)/sizeof(rng[0]);
73 for (int j = 0; j < N; ++j)
74 test<std::deque<MoveOnly, min_allocator<MoveOnly>> >(rng[j]);
75 }
76
77 return 0;
78 }
79