Home | History | Annotate | Download | only in forwardlist.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 // <forward_list>
     11 
     12 // void resize(size_type n);
     13 
     14 #include <forward_list>
     15 #include <cassert>
     16 
     17 #include "DefaultOnly.h"
     18 #include "min_allocator.h"
     19 
     20 int main()
     21 {
     22     {
     23         typedef DefaultOnly T;
     24         typedef std::forward_list<T> C;
     25         C c;
     26         c.resize(0);
     27         assert(distance(c.begin(), c.end()) == 0);
     28         c.resize(10);
     29         assert(distance(c.begin(), c.end()) == 10);
     30         c.resize(20);
     31         assert(distance(c.begin(), c.end()) == 20);
     32         c.resize(5);
     33         assert(distance(c.begin(), c.end()) == 5);
     34         c.resize(0);
     35         assert(distance(c.begin(), c.end()) == 0);
     36     }
     37     {
     38         typedef int T;
     39         typedef std::forward_list<T> C;
     40         const T t[] = {0, 1, 2, 3, 4};
     41         C c(std::begin(t), std::end(t));
     42 
     43         c.resize(3);
     44         assert(distance(c.begin(), c.end()) == 3);
     45         assert(*next(c.begin(), 0) == 0);
     46         assert(*next(c.begin(), 1) == 1);
     47         assert(*next(c.begin(), 2) == 2);
     48 
     49         c.resize(6);
     50         assert(distance(c.begin(), c.end()) == 6);
     51         assert(*next(c.begin(), 0) == 0);
     52         assert(*next(c.begin(), 1) == 1);
     53         assert(*next(c.begin(), 2) == 2);
     54         assert(*next(c.begin(), 3) == 0);
     55         assert(*next(c.begin(), 4) == 0);
     56         assert(*next(c.begin(), 5) == 0);
     57 
     58         c.resize(6);
     59         assert(distance(c.begin(), c.end()) == 6);
     60         assert(*next(c.begin(), 0) == 0);
     61         assert(*next(c.begin(), 1) == 1);
     62         assert(*next(c.begin(), 2) == 2);
     63         assert(*next(c.begin(), 3) == 0);
     64         assert(*next(c.begin(), 4) == 0);
     65         assert(*next(c.begin(), 5) == 0);
     66     }
     67 #if TEST_STD_VER >= 11
     68     {
     69         typedef DefaultOnly T;
     70         typedef std::forward_list<T, min_allocator<T>> C;
     71         C c;
     72         c.resize(0);
     73         assert(distance(c.begin(), c.end()) == 0);
     74         c.resize(10);
     75         assert(distance(c.begin(), c.end()) == 10);
     76         c.resize(20);
     77         assert(distance(c.begin(), c.end()) == 20);
     78         c.resize(5);
     79         assert(distance(c.begin(), c.end()) == 5);
     80         c.resize(0);
     81         assert(distance(c.begin(), c.end()) == 0);
     82     }
     83     {
     84         typedef int T;
     85         typedef std::forward_list<T, min_allocator<T>> C;
     86         const T t[] = {0, 1, 2, 3, 4};
     87         C c(std::begin(t), std::end(t));
     88 
     89         c.resize(3);
     90         assert(distance(c.begin(), c.end()) == 3);
     91         assert(*next(c.begin(), 0) == 0);
     92         assert(*next(c.begin(), 1) == 1);
     93         assert(*next(c.begin(), 2) == 2);
     94 
     95         c.resize(6);
     96         assert(distance(c.begin(), c.end()) == 6);
     97         assert(*next(c.begin(), 0) == 0);
     98         assert(*next(c.begin(), 1) == 1);
     99         assert(*next(c.begin(), 2) == 2);
    100         assert(*next(c.begin(), 3) == 0);
    101         assert(*next(c.begin(), 4) == 0);
    102         assert(*next(c.begin(), 5) == 0);
    103 
    104         c.resize(6);
    105         assert(distance(c.begin(), c.end()) == 6);
    106         assert(*next(c.begin(), 0) == 0);
    107         assert(*next(c.begin(), 1) == 1);
    108         assert(*next(c.begin(), 2) == 2);
    109         assert(*next(c.begin(), 3) == 0);
    110         assert(*next(c.begin(), 4) == 0);
    111         assert(*next(c.begin(), 5) == 0);
    112     }
    113 #endif
    114 }
    115