• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // <deque>
11 
12 // void push_front(value_type&& v);
13 
14 #include <deque>
15 #include <cassert>
16 
17 #include "MoveOnly.h"
18 #include "min_allocator.h"
19 
20 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
21 
22 template <class C>
23 C
make(int size,int start=0)24 make(int size, int start = 0 )
25 {
26     const int b = 4096 / sizeof(int);
27     int init = 0;
28     if (start > 0)
29     {
30         init = (start+1) / b + ((start+1) % b != 0);
31         init *= b;
32         --init;
33     }
34     C c(init);
35     for (int i = 0; i < init-start; ++i)
36         c.pop_back();
37     for (int i = 0; i < size; ++i)
38         c.push_back(MoveOnly(i));
39     for (int i = 0; i < start; ++i)
40         c.pop_front();
41     return c;
42 }
43 
44 template <class C>
45 void
test(C & c1,int x)46 test(C& c1, int x)
47 {
48     typedef typename C::iterator I;
49     std::size_t c1_osize = c1.size();
50     c1.push_front(MoveOnly(x));
51     assert(c1.size() == c1_osize + 1);
52     assert(distance(c1.begin(), c1.end()) == c1.size());
53     I i = c1.begin();
54     assert(*i == MoveOnly(x));
55     ++i;
56     for (int j = 0; j < c1_osize; ++j, ++i)
57         assert(*i == MoveOnly(j));
58 }
59 
60 template <class C>
61 void
testN(int start,int N)62 testN(int start, int N)
63 {
64     C c1 = make<C>(N, start);
65     test(c1, -10);
66 }
67 
68 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
69 
main()70 int main()
71 {
72 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
73     {
74     int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
75     const int N = sizeof(rng)/sizeof(rng[0]);
76     for (int i = 0; i < N; ++i)
77         for (int j = 0; j < N; ++j)
78             testN<std::deque<MoveOnly> >(rng[i], rng[j]);
79     }
80 #if __cplusplus >= 201103L
81     {
82     int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
83     const int N = sizeof(rng)/sizeof(rng[0]);
84     for (int i = 0; i < N; ++i)
85         for (int j = 0; j < N; ++j)
86             testN<std::deque<MoveOnly, min_allocator<MoveOnly>> >(rng[i], rng[j]);
87     }
88 #endif
89 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
90 }
91