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