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