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, const value_type& v);
     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 int T;
     24         typedef std::forward_list<T> C;
     25         const T t[] = {0, 1, 2, 3, 4};
     26         C c(std::begin(t), std::end(t));
     27 
     28         c.resize(3, 10);
     29         assert(distance(c.begin(), c.end()) == 3);
     30         assert(*next(c.begin(), 0) == 0);
     31         assert(*next(c.begin(), 1) == 1);
     32         assert(*next(c.begin(), 2) == 2);
     33 
     34         c.resize(6, 10);
     35         assert(distance(c.begin(), c.end()) == 6);
     36         assert(*next(c.begin(), 0) == 0);
     37         assert(*next(c.begin(), 1) == 1);
     38         assert(*next(c.begin(), 2) == 2);
     39         assert(*next(c.begin(), 3) == 10);
     40         assert(*next(c.begin(), 4) == 10);
     41         assert(*next(c.begin(), 5) == 10);
     42 
     43         c.resize(6, 12);
     44         assert(distance(c.begin(), c.end()) == 6);
     45         assert(*next(c.begin(), 0) == 0);
     46         assert(*next(c.begin(), 1) == 1);
     47         assert(*next(c.begin(), 2) == 2);
     48         assert(*next(c.begin(), 3) == 10);
     49         assert(*next(c.begin(), 4) == 10);
     50         assert(*next(c.begin(), 5) == 10);
     51     }
     52 #if __cplusplus >= 201103L
     53     {
     54         typedef int T;
     55         typedef std::forward_list<T, min_allocator<T>> C;
     56         const T t[] = {0, 1, 2, 3, 4};
     57         C c(std::begin(t), std::end(t));
     58 
     59         c.resize(3, 10);
     60         assert(distance(c.begin(), c.end()) == 3);
     61         assert(*next(c.begin(), 0) == 0);
     62         assert(*next(c.begin(), 1) == 1);
     63         assert(*next(c.begin(), 2) == 2);
     64 
     65         c.resize(6, 10);
     66         assert(distance(c.begin(), c.end()) == 6);
     67         assert(*next(c.begin(), 0) == 0);
     68         assert(*next(c.begin(), 1) == 1);
     69         assert(*next(c.begin(), 2) == 2);
     70         assert(*next(c.begin(), 3) == 10);
     71         assert(*next(c.begin(), 4) == 10);
     72         assert(*next(c.begin(), 5) == 10);
     73 
     74         c.resize(6, 12);
     75         assert(distance(c.begin(), c.end()) == 6);
     76         assert(*next(c.begin(), 0) == 0);
     77         assert(*next(c.begin(), 1) == 1);
     78         assert(*next(c.begin(), 2) == 2);
     79         assert(*next(c.begin(), 3) == 10);
     80         assert(*next(c.begin(), 4) == 10);
     81         assert(*next(c.begin(), 5) == 10);
     82     }
     83 #endif
     84 }
     85