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