1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // UNSUPPORTED: c++98, c++03
11
12 // <deque>
13
14 // void push_back(value_type&& v);
15 // void pop_back();
16 // void pop_front();
17
18 #include <deque>
19 #include <cassert>
20
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, ++it)
57 assert(*it == MoveOnly(i));
58 }
59 }
60
61
main()62 int main()
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