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, value_type&& v);
     13 
     14 #include <forward_list>
     15 #include <cassert>
     16 
     17 #include "MoveOnly.h"
     18 #include "min_allocator.h"
     19 
     20 int main()
     21 {
     22 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     23     {
     24         typedef MoveOnly T;
     25         typedef std::forward_list<T> C;
     26         typedef C::iterator I;
     27         C c;
     28         I i = c.insert_after(c.cbefore_begin(), 0);
     29         assert(i == c.begin());
     30         assert(c.front() == 0);
     31         assert(c.front() == 0);
     32         assert(distance(c.begin(), c.end()) == 1);
     33 
     34         i = c.insert_after(c.cbegin(), 1);
     35         assert(i == next(c.begin()));
     36         assert(c.front() == 0);
     37         assert(*next(c.begin()) == 1);
     38         assert(distance(c.begin(), c.end()) == 2);
     39 
     40         i = c.insert_after(next(c.cbegin()), 2);
     41         assert(i == next(c.begin(), 2));
     42         assert(c.front() == 0);
     43         assert(*next(c.begin()) == 1);
     44         assert(*next(c.begin(), 2) == 2);
     45         assert(distance(c.begin(), c.end()) == 3);
     46 
     47         i = c.insert_after(c.cbegin(), 3);
     48         assert(i == next(c.begin()));
     49         assert(c.front() == 0);
     50         assert(*next(c.begin(), 1) == 3);
     51         assert(*next(c.begin(), 2) == 1);
     52         assert(*next(c.begin(), 3) == 2);
     53         assert(distance(c.begin(), c.end()) == 4);
     54     }
     55 #if __cplusplus >= 201103L
     56     {
     57         typedef MoveOnly T;
     58         typedef std::forward_list<T, min_allocator<T>> C;
     59         typedef C::iterator I;
     60         C c;
     61         I i = c.insert_after(c.cbefore_begin(), 0);
     62         assert(i == c.begin());
     63         assert(c.front() == 0);
     64         assert(c.front() == 0);
     65         assert(distance(c.begin(), c.end()) == 1);
     66 
     67         i = c.insert_after(c.cbegin(), 1);
     68         assert(i == next(c.begin()));
     69         assert(c.front() == 0);
     70         assert(*next(c.begin()) == 1);
     71         assert(distance(c.begin(), c.end()) == 2);
     72 
     73         i = c.insert_after(next(c.cbegin()), 2);
     74         assert(i == next(c.begin(), 2));
     75         assert(c.front() == 0);
     76         assert(*next(c.begin()) == 1);
     77         assert(*next(c.begin(), 2) == 2);
     78         assert(distance(c.begin(), c.end()) == 3);
     79 
     80         i = c.insert_after(c.cbegin(), 3);
     81         assert(i == next(c.begin()));
     82         assert(c.front() == 0);
     83         assert(*next(c.begin(), 1) == 3);
     84         assert(*next(c.begin(), 2) == 1);
     85         assert(*next(c.begin(), 3) == 2);
     86         assert(distance(c.begin(), c.end()) == 4);
     87     }
     88 #endif
     89 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     90 }
     91