| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <list> |
| 10 | |
| 11 | // iterator begin(); |
| 12 | // iterator end(); |
| 13 | // const_iterator begin() const; |
| 14 | // const_iterator end() const; |
| 15 | // const_iterator cbegin() const; |
| 16 | // const_iterator cend() const; |
| 17 | |
| 18 | #include <list> |
| 19 | #include <cassert> |
| 20 | #include <iterator> |
| 21 | |
| 22 | #include "test_macros.h" |
| 23 | #include "min_allocator.h" |
| 24 | |
| 25 | struct A { |
| 26 | int first; |
| 27 | int second; |
| 28 | }; |
| 29 | |
| 30 | int main(int, char**) { |
| 31 | { |
| 32 | typedef int T; |
| 33 | typedef std::list<T> C; |
| 34 | C c; |
| 35 | C::iterator i = c.begin(); |
| 36 | C::iterator j = c.end(); |
| 37 | assert(std::distance(i, j) == 0); |
| 38 | assert(i == j); |
| 39 | } |
| 40 | { |
| 41 | typedef int T; |
| 42 | typedef std::list<T> C; |
| 43 | const C c; |
| 44 | C::const_iterator i = c.begin(); |
| 45 | C::const_iterator j = c.end(); |
| 46 | assert(std::distance(i, j) == 0); |
| 47 | assert(i == j); |
| 48 | } |
| 49 | { |
| 50 | typedef int T; |
| 51 | typedef std::list<T> C; |
| 52 | C c; |
| 53 | C::const_iterator i = c.cbegin(); |
| 54 | C::const_iterator j = c.cend(); |
| 55 | assert(std::distance(i, j) == 0); |
| 56 | assert(i == j); |
| 57 | assert(i == c.end()); |
| 58 | } |
| 59 | { |
| 60 | typedef int T; |
| 61 | typedef std::list<T> C; |
| 62 | const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
| 63 | C c(std::begin(arr: t), std::end(arr: t)); |
| 64 | C::iterator i = c.begin(); |
| 65 | assert(*i == 0); |
| 66 | ++i; |
| 67 | assert(*i == 1); |
| 68 | *i = 10; |
| 69 | assert(*i == 10); |
| 70 | assert(std::distance(c.begin(), c.end()) == 10); |
| 71 | } |
| 72 | { |
| 73 | typedef int T; |
| 74 | typedef std::list<T> C; |
| 75 | C::iterator i; |
| 76 | C::const_iterator j; |
| 77 | } |
| 78 | #if TEST_STD_VER >= 11 |
| 79 | { |
| 80 | typedef int T; |
| 81 | typedef std::list<T, min_allocator<T>> C; |
| 82 | C c; |
| 83 | C::iterator i = c.begin(); |
| 84 | C::iterator j = c.end(); |
| 85 | assert(std::distance(i, j) == 0); |
| 86 | assert(i == j); |
| 87 | } |
| 88 | { |
| 89 | typedef int T; |
| 90 | typedef std::list<T, min_allocator<T>> C; |
| 91 | const C c; |
| 92 | C::const_iterator i = c.begin(); |
| 93 | C::const_iterator j = c.end(); |
| 94 | assert(std::distance(i, j) == 0); |
| 95 | assert(i == j); |
| 96 | } |
| 97 | { |
| 98 | typedef int T; |
| 99 | typedef std::list<T, min_allocator<T>> C; |
| 100 | C c; |
| 101 | C::const_iterator i = c.cbegin(); |
| 102 | C::const_iterator j = c.cend(); |
| 103 | assert(std::distance(i, j) == 0); |
| 104 | assert(i == j); |
| 105 | assert(i == c.end()); |
| 106 | } |
| 107 | { |
| 108 | typedef int T; |
| 109 | typedef std::list<T, min_allocator<T>> C; |
| 110 | const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
| 111 | C c(std::begin(t), std::end(t)); |
| 112 | C::iterator i = c.begin(); |
| 113 | assert(*i == 0); |
| 114 | ++i; |
| 115 | assert(*i == 1); |
| 116 | *i = 10; |
| 117 | assert(*i == 10); |
| 118 | assert(std::distance(c.begin(), c.end()) == 10); |
| 119 | } |
| 120 | { |
| 121 | typedef int T; |
| 122 | typedef std::list<T, min_allocator<T>> C; |
| 123 | C::iterator i; |
| 124 | C::const_iterator j; |
| 125 | } |
| 126 | { |
| 127 | typedef A T; |
| 128 | typedef std::list<T, min_allocator<T>> C; |
| 129 | C c = {A{1, 2}}; |
| 130 | C::iterator i = c.begin(); |
| 131 | i->first = 3; |
| 132 | C::const_iterator j = i; |
| 133 | assert(j->first == 3); |
| 134 | } |
| 135 | #endif |
| 136 | #if TEST_STD_VER > 11 |
| 137 | { |
| 138 | std::list<int>::iterator ii1{}, ii2{}; |
| 139 | std::list<int>::iterator ii4 = ii1; |
| 140 | std::list<int>::const_iterator cii{}; |
| 141 | assert(ii1 == ii2); |
| 142 | assert(ii1 == ii4); |
| 143 | |
| 144 | assert(!(ii1 != ii2)); |
| 145 | |
| 146 | assert((ii1 == cii)); |
| 147 | assert((cii == ii1)); |
| 148 | assert(!(ii1 != cii)); |
| 149 | assert(!(cii != ii1)); |
| 150 | } |
| 151 | #endif |
| 152 | |
| 153 | return 0; |
| 154 | } |
| 155 | |