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 
     21 int main()
     22 {
     23     {
     24         typedef int T;
     25         typedef std::forward_list<T> C;
     26         typedef C::iterator I;
     27         typedef input_iterator<const T*> J;
     28         C c;
     29         const T t[] = {0, 1, 2, 3, 4};
     30         I i = c.insert_after(c.cbefore_begin(), J(t), J(t));
     31         assert(i == c.before_begin());
     32         assert(distance(c.begin(), c.end()) == 0);
     33 
     34         i = c.insert_after(c.cbefore_begin(), J(t), J(t+3));
     35         assert(i == next(c.before_begin(), 3));
     36         assert(distance(c.begin(), c.end()) == 3);
     37         assert(*next(c.begin(), 0) == 0);
     38         assert(*next(c.begin(), 1) == 1);
     39         assert(*next(c.begin(), 2) == 2);
     40 
     41         i = c.insert_after(c.begin(), J(t+3), J(t+5));
     42         assert(i == next(c.begin(), 2));
     43         assert(distance(c.begin(), c.end()) == 5);
     44         assert(*next(c.begin(), 0) == 0);
     45         assert(*next(c.begin(), 1) == 3);
     46         assert(*next(c.begin(), 2) == 4);
     47         assert(*next(c.begin(), 3) == 1);
     48         assert(*next(c.begin(), 4) == 2);
     49     }
     50 }
     51