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