Home | History | Annotate | Download | only in deque.capacity
      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 //       reference operator[](size_type __i);
     13 // const_reference operator[](size_type __i) const;
     14 //
     15 //       reference at(size_type __i);
     16 // const_reference at(size_type __i) const;
     17 //
     18 //       reference front();
     19 // const_reference front() const;
     20 //
     21 //       reference back();
     22 // const_reference back() const;
     23 
     24 #include <deque>
     25 #include <cassert>
     26 
     27 #include "min_allocator.h"
     28 
     29 template <class C>
     30 C
     31 make(int size, int start = 0 )
     32 {
     33     const int b = 4096 / sizeof(int);
     34     int init = 0;
     35     if (start > 0)
     36     {
     37         init = (start+1) / b + ((start+1) % b != 0);
     38         init *= b;
     39         --init;
     40     }
     41     C c(init, 0);
     42     for (int i = 0; i < init-start; ++i)
     43         c.pop_back();
     44     for (int i = 0; i < size; ++i)
     45         c.push_back(i);
     46     for (int i = 0; i < start; ++i)
     47         c.pop_front();
     48     return c;
     49 };
     50 
     51 int main()
     52 {
     53     {
     54         std::deque<int> c = make<std::deque<int> >(10);
     55         for (unsigned i = 0; i < 10; ++i)
     56             assert(c[i] == i);
     57         for (unsigned i = 0; i < 10; ++i)
     58             assert(c.at(i) == i);
     59         assert(c.front() == 0);
     60         assert(c.back() == 9);
     61     }
     62     {
     63         const std::deque<int> c = make<std::deque<int> >(10);
     64         for (unsigned i = 0; i < 10; ++i)
     65             assert(c[i] == i);
     66         for (unsigned i = 0; i < 10; ++i)
     67             assert(c.at(i) == i);
     68         assert(c.front() == 0);
     69         assert(c.back() == 9);
     70     }
     71 #if __cplusplus >= 201103L
     72     {
     73         std::deque<int, min_allocator<int>> c = make<std::deque<int, min_allocator<int>> >(10);
     74         for (unsigned i = 0; i < 10; ++i)
     75             assert(c[i] == i);
     76         for (unsigned i = 0; i < 10; ++i)
     77             assert(c.at(i) == i);
     78         assert(c.front() == 0);
     79         assert(c.back() == 9);
     80     }
     81     {
     82         const std::deque<int, min_allocator<int>> c = make<std::deque<int, min_allocator<int>> >(10);
     83         for (unsigned i = 0; i < 10; ++i)
     84             assert(c[i] == i);
     85         for (unsigned i = 0; i < 10; ++i)
     86             assert(c.at(i) == i);
     87         assert(c.front() == 0);
     88         assert(c.back() == 9);
     89     }
     90 #endif
     91 }
     92