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(const value_type& v);
     13 // void pop_back();
     14 // void pop_front();
     15 
     16 #include <deque>
     17 #include <cassert>
     18 
     19 std::deque<int>
     20 make(int size, int start = 0 )
     21 {
     22     const int b = 4096 / sizeof(int);
     23     int init = 0;
     24     if (start > 0)
     25     {
     26         init = (start+1) / b + ((start+1) % b != 0);
     27         init *= b;
     28         --init;
     29     }
     30     std::deque<int> c(init, 0);
     31     for (int i = 0; i < init-start; ++i)
     32         c.pop_back();
     33     for (int i = 0; i < size; ++i)
     34         c.push_back(i);
     35     for (int i = 0; i < start; ++i)
     36         c.pop_front();
     37     return c;
     38 };
     39 
     40 void test(int size)
     41 {
     42     int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049};
     43     const int N = sizeof(rng)/sizeof(rng[0]);
     44     for (int j = 0; j < N; ++j)
     45     {
     46         std::deque<int> c = make(size, rng[j]);
     47         std::deque<int>::const_iterator it = c.begin();
     48         for (int i = 0; i < size; ++i, ++it)
     49             assert(*it == i);
     50     }
     51 }
     52 
     53 int main()
     54 {
     55     int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049, 4094, 4095, 4096};
     56     const int N = sizeof(rng)/sizeof(rng[0]);
     57     for (int j = 0; j < N; ++j)
     58         test(rng[j]);
     59 }
     60