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