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