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_front(const value_type& v);
     13 
     14 #include <deque>
     15 #include <cassert>
     16 
     17 std::deque<int>
     18 make(int size, int start = 0 )
     19 {
     20     const int b = 4096 / sizeof(int);
     21     int init = 0;
     22     if (start > 0)
     23     {
     24         init = (start+1) / b + ((start+1) % b != 0);
     25         init *= b;
     26         --init;
     27     }
     28     std::deque<int> c(init, 0);
     29     for (int i = 0; i < init-start; ++i)
     30         c.pop_back();
     31     for (int i = 0; i < size; ++i)
     32         c.push_back(i);
     33     for (int i = 0; i < start; ++i)
     34         c.pop_front();
     35     return c;
     36 };
     37 
     38 void
     39 test(std::deque<int>& c1, int x)
     40 {
     41     typedef std::deque<int> C;
     42     typedef C::iterator I;
     43     std::size_t c1_osize = c1.size();
     44     c1.push_front(x);
     45     assert(c1.size() == c1_osize + 1);
     46     assert(distance(c1.begin(), c1.end()) == c1.size());
     47     I i = c1.begin();
     48     assert(*i == x);
     49     ++i;
     50     for (int j = 0; j < c1_osize; ++j, ++i)
     51         assert(*i == j);
     52 }
     53 
     54 void
     55 testN(int start, int N)
     56 {
     57     typedef std::deque<int> C;
     58     C c1 = make(N, start);
     59     test(c1, -10);
     60 }
     61 
     62 int main()
     63 {
     64     int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
     65     const int N = sizeof(rng)/sizeof(rng[0]);
     66     for (int i = 0; i < N; ++i)
     67         for (int j = 0; j < N; ++j)
     68             testN(rng[i], rng[j]);
     69 }
     70