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 pop_front()
     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)
     40 {
     41     typedef std::deque<int> C;
     42     typedef C::iterator I;
     43     std::size_t c1_osize = c1.size();
     44     c1.pop_front();
     45     assert(c1.size() == c1_osize - 1);
     46     assert(distance(c1.begin(), c1.end()) == c1.size());
     47     I i = c1.begin();
     48     for (int j = 1; j < c1.size(); ++j, ++i)
     49         assert(*i == j);
     50 }
     51 
     52 void
     53 testN(int start, int N)
     54 {
     55     if (N != 0)
     56     {
     57         typedef std::deque<int> C;
     58         C c1 = make(N, start);
     59         test(c1);
     60     }
     61 }
     62 
     63 int main()
     64 {
     65     int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
     66     const int N = sizeof(rng)/sizeof(rng[0]);
     67     for (int i = 0; i < N; ++i)
     68         for (int j = 0; j < N; ++j)
     69             testN(rng[i], rng[j]);
     70 }
     71