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 begin(); 13 // iterator end(); 14 // const_iterator begin() const; 15 // const_iterator end() const; 16 // const_iterator cbegin() const; 17 // const_iterator cend() const; 18 19 #include <forward_list> 20 #include <cassert> 21 #include <iterator> 22 23 #include "min_allocator.h" 24 25 int main() 26 { 27 { 28 typedef int T; 29 typedef std::forward_list<T> C; 30 C c; 31 C::iterator i = c.begin(); 32 C::iterator j = c.end(); 33 assert(std::distance(i, j) == 0); 34 assert(i == j); 35 } 36 { 37 typedef int T; 38 typedef std::forward_list<T> C; 39 const C c; 40 C::const_iterator i = c.begin(); 41 C::const_iterator j = c.end(); 42 assert(std::distance(i, j) == 0); 43 assert(i == j); 44 } 45 { 46 typedef int T; 47 typedef std::forward_list<T> C; 48 C c; 49 C::const_iterator i = c.cbegin(); 50 C::const_iterator j = c.cend(); 51 assert(std::distance(i, j) == 0); 52 assert(i == j); 53 assert(i == c.end()); 54 } 55 { 56 typedef int T; 57 typedef std::forward_list<T> C; 58 const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 59 C c(std::begin(t), std::end(t)); 60 C::iterator i = c.begin(); 61 assert(*i == 0); 62 ++i; 63 assert(*i == 1); 64 *i = 10; 65 assert(*i == 10); 66 assert(std::distance(c.begin(), c.end()) == 10); 67 } 68 { 69 typedef int T; 70 typedef std::forward_list<T> C; 71 C::iterator i; 72 C::const_iterator j; 73 } 74 #if __cplusplus >= 201103L 75 { 76 typedef int T; 77 typedef std::forward_list<T, min_allocator<T>> C; 78 C c; 79 C::iterator i = c.begin(); 80 C::iterator j = c.end(); 81 assert(std::distance(i, j) == 0); 82 assert(i == j); 83 } 84 { 85 typedef int T; 86 typedef std::forward_list<T, min_allocator<T>> C; 87 const C c; 88 C::const_iterator i = c.begin(); 89 C::const_iterator j = c.end(); 90 assert(std::distance(i, j) == 0); 91 assert(i == j); 92 } 93 { 94 typedef int T; 95 typedef std::forward_list<T, min_allocator<T>> C; 96 C c; 97 C::const_iterator i = c.cbegin(); 98 C::const_iterator j = c.cend(); 99 assert(std::distance(i, j) == 0); 100 assert(i == j); 101 assert(i == c.end()); 102 } 103 { 104 typedef int T; 105 typedef std::forward_list<T, min_allocator<T>> C; 106 const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 107 C c(std::begin(t), std::end(t)); 108 C::iterator i = c.begin(); 109 assert(*i == 0); 110 ++i; 111 assert(*i == 1); 112 *i = 10; 113 assert(*i == 10); 114 assert(std::distance(c.begin(), c.end()) == 10); 115 } 116 { 117 typedef int T; 118 typedef std::forward_list<T, min_allocator<T>> C; 119 C::iterator i; 120 C::const_iterator j; 121 } 122 #endif 123 #if _LIBCPP_STD_VER > 11 124 { // N3644 testing 125 std::forward_list<int>::iterator ii1{}, ii2{}; 126 std::forward_list<int>::iterator ii4 = ii1; 127 std::forward_list<int>::const_iterator cii{}; 128 assert ( ii1 == ii2 ); 129 assert ( ii1 == ii4 ); 130 131 assert (!(ii1 != ii2 )); 132 133 assert ( (ii1 == cii )); 134 assert ( (cii == ii1 )); 135 assert (!(ii1 != cii )); 136 assert (!(cii != ii1 )); 137 138 // std::forward_list<int> c; 139 // assert ( ii1 != c.cbegin()); 140 // assert ( cii != c.begin()); 141 // assert ( cii != c.cend()); 142 // assert ( ii1 != c.end()); 143 } 144 #endif 145 } 146