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