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 // iterator insert_after(const_iterator p, size_type n, const value_type& v);
     13 
     14 #include <forward_list>
     15 #include <cassert>
     16 
     17 #include "min_allocator.h"
     18 
     19 int main()
     20 {
     21     {
     22         typedef int T;
     23         typedef std::forward_list<T> C;
     24         typedef C::iterator I;
     25         C c;
     26         I i = c.insert_after(c.cbefore_begin(), 0, 0);
     27         assert(i == c.before_begin());
     28         assert(distance(c.begin(), c.end()) == 0);
     29 
     30         i = c.insert_after(c.cbefore_begin(), 3, 3);
     31         assert(i == next(c.before_begin(), 3));
     32         assert(distance(c.begin(), c.end()) == 3);
     33         assert(*next(c.begin(), 0) == 3);
     34         assert(*next(c.begin(), 1) == 3);
     35         assert(*next(c.begin(), 2) == 3);
     36 
     37         i = c.insert_after(c.begin(), 2, 2);
     38         assert(i == next(c.begin(), 2));
     39         assert(distance(c.begin(), c.end()) == 5);
     40         assert(*next(c.begin(), 0) == 3);
     41         assert(*next(c.begin(), 1) == 2);
     42         assert(*next(c.begin(), 2) == 2);
     43         assert(*next(c.begin(), 3) == 3);
     44         assert(*next(c.begin(), 4) == 3);
     45     }
     46 #if TEST_STD_VER >= 11
     47     {
     48         typedef int T;
     49         typedef std::forward_list<T, min_allocator<T>> C;
     50         typedef C::iterator I;
     51         C c;
     52         I i = c.insert_after(c.cbefore_begin(), 0, 0);
     53         assert(i == c.before_begin());
     54         assert(distance(c.begin(), c.end()) == 0);
     55 
     56         i = c.insert_after(c.cbefore_begin(), 3, 3);
     57         assert(i == next(c.before_begin(), 3));
     58         assert(distance(c.begin(), c.end()) == 3);
     59         assert(*next(c.begin(), 0) == 3);
     60         assert(*next(c.begin(), 1) == 3);
     61         assert(*next(c.begin(), 2) == 3);
     62 
     63         i = c.insert_after(c.begin(), 2, 2);
     64         assert(i == next(c.begin(), 2));
     65         assert(distance(c.begin(), c.end()) == 5);
     66         assert(*next(c.begin(), 0) == 3);
     67         assert(*next(c.begin(), 1) == 2);
     68         assert(*next(c.begin(), 2) == 2);
     69         assert(*next(c.begin(), 3) == 3);
     70         assert(*next(c.begin(), 4) == 3);
     71     }
     72 #endif
     73 }
     74