| 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 | // <vector> |
| 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 <vector> |
| 19 | #include <cassert> |
| 20 | #include <iterator> |
| 21 | |
| 22 | #include "test_macros.h" |
| 23 | #include "min_allocator.h" |
| 24 | |
| 25 | TEST_CONSTEXPR_CXX20 bool tests() { |
| 26 | using IterRefT = std::iterator_traits<std::vector<bool>::iterator>::reference; |
| 27 | ASSERT_SAME_TYPE(IterRefT, std::vector<bool>::reference); |
| 28 | |
| 29 | using ConstIterRefT = std::iterator_traits<std::vector<bool>::const_iterator>::reference; |
| 30 | #if !defined(_LIBCPP_VERSION) || defined(_LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL) |
| 31 | ASSERT_SAME_TYPE(ConstIterRefT, bool); |
| 32 | #else |
| 33 | ASSERT_SAME_TYPE(ConstIterRefT, std::__bit_const_reference<std::vector<bool> >); |
| 34 | #endif |
| 35 | { |
| 36 | typedef bool T; |
| 37 | typedef std::vector<T> C; |
| 38 | C c; |
| 39 | C::iterator i = c.begin(); |
| 40 | C::iterator j = c.end(); |
| 41 | assert(std::distance(i, j) == 0); |
| 42 | assert(i == j); |
| 43 | } |
| 44 | { |
| 45 | typedef bool T; |
| 46 | typedef std::vector<T> C; |
| 47 | const C c; |
| 48 | C::const_iterator i = c.begin(); |
| 49 | C::const_iterator j = c.end(); |
| 50 | assert(std::distance(i, j) == 0); |
| 51 | assert(i == j); |
| 52 | } |
| 53 | { |
| 54 | typedef bool T; |
| 55 | typedef std::vector<T> C; |
| 56 | C c; |
| 57 | C::const_iterator i = c.cbegin(); |
| 58 | C::const_iterator j = c.cend(); |
| 59 | assert(std::distance(i, j) == 0); |
| 60 | assert(i == j); |
| 61 | assert(i == c.end()); |
| 62 | } |
| 63 | { |
| 64 | typedef bool T; |
| 65 | typedef std::vector<T> C; |
| 66 | C::iterator i; |
| 67 | C::const_iterator j; |
| 68 | (void)i; |
| 69 | (void)j; |
| 70 | } |
| 71 | #if TEST_STD_VER >= 11 |
| 72 | { |
| 73 | typedef bool T; |
| 74 | typedef std::vector<T, min_allocator<T>> C; |
| 75 | C c; |
| 76 | C::iterator i = c.begin(); |
| 77 | C::iterator j = c.end(); |
| 78 | assert(std::distance(i, j) == 0); |
| 79 | |
| 80 | assert(i == j); |
| 81 | assert(!(i != j)); |
| 82 | |
| 83 | assert(!(i < j)); |
| 84 | assert((i <= j)); |
| 85 | |
| 86 | assert(!(i > j)); |
| 87 | assert((i >= j)); |
| 88 | |
| 89 | # if TEST_STD_VER >= 20 |
| 90 | // P1614 + LWG3352 |
| 91 | std::same_as<std::strong_ordering> decltype(auto) r = i <=> j; |
| 92 | assert(r == std::strong_ordering::equal); |
| 93 | # endif |
| 94 | } |
| 95 | { |
| 96 | typedef bool T; |
| 97 | typedef std::vector<T, min_allocator<T>> C; |
| 98 | const C c; |
| 99 | C::const_iterator i = c.begin(); |
| 100 | C::const_iterator j = c.end(); |
| 101 | assert(std::distance(i, j) == 0); |
| 102 | |
| 103 | assert(i == j); |
| 104 | assert(!(i != j)); |
| 105 | |
| 106 | assert(!(i < j)); |
| 107 | assert((i <= j)); |
| 108 | |
| 109 | assert(!(i > j)); |
| 110 | assert((i >= j)); |
| 111 | |
| 112 | # if TEST_STD_VER >= 20 |
| 113 | // P1614 + LWG3352 |
| 114 | std::same_as<std::strong_ordering> decltype(auto) r = i <=> j; |
| 115 | assert(r == std::strong_ordering::equal); |
| 116 | # endif |
| 117 | } |
| 118 | { |
| 119 | typedef bool T; |
| 120 | typedef std::vector<T, min_allocator<T>> C; |
| 121 | C c; |
| 122 | C::const_iterator i = c.cbegin(); |
| 123 | C::const_iterator j = c.cend(); |
| 124 | assert(std::distance(i, j) == 0); |
| 125 | assert(i == j); |
| 126 | assert(i == c.end()); |
| 127 | } |
| 128 | { |
| 129 | typedef bool T; |
| 130 | typedef std::vector<T, min_allocator<T>> C; |
| 131 | C::iterator i; |
| 132 | C::const_iterator j; |
| 133 | (void)i; |
| 134 | (void)j; |
| 135 | } |
| 136 | #endif |
| 137 | #if TEST_STD_VER > 11 |
| 138 | { // N3644 testing |
| 139 | std::vector<bool>::iterator ii1{}, ii2{}; |
| 140 | std::vector<bool>::iterator ii4 = ii1; |
| 141 | std::vector<bool>::const_iterator cii{}; |
| 142 | assert(ii1 == ii2); |
| 143 | assert(ii1 == ii4); |
| 144 | |
| 145 | assert(!(ii1 != ii2)); |
| 146 | |
| 147 | assert((ii1 == cii)); |
| 148 | assert((cii == ii1)); |
| 149 | assert(!(ii1 != cii)); |
| 150 | assert(!(cii != ii1)); |
| 151 | assert(!(ii1 < cii)); |
| 152 | assert(!(cii < ii1)); |
| 153 | assert((ii1 <= cii)); |
| 154 | assert((cii <= ii1)); |
| 155 | assert(!(ii1 > cii)); |
| 156 | assert(!(cii > ii1)); |
| 157 | assert((ii1 >= cii)); |
| 158 | assert((cii >= ii1)); |
| 159 | assert(cii - ii1 == 0); |
| 160 | assert(ii1 - cii == 0); |
| 161 | |
| 162 | # if TEST_STD_VER >= 20 |
| 163 | // P1614 + LWG3352 |
| 164 | std::same_as<std::strong_ordering> decltype(auto) r1 = ii1 <=> ii2; |
| 165 | assert(r1 == std::strong_ordering::equal); |
| 166 | |
| 167 | std::same_as<std::strong_ordering> decltype(auto) r2 = cii <=> ii2; |
| 168 | assert(r2 == std::strong_ordering::equal); |
| 169 | # endif // TEST_STD_VER > 20 |
| 170 | } |
| 171 | #endif |
| 172 | |
| 173 | return true; |
| 174 | } |
| 175 | |
| 176 | int main(int, char**) { |
| 177 | tests(); |
| 178 | #if TEST_STD_VER > 17 |
| 179 | static_assert(tests()); |
| 180 | #endif |
| 181 | return 0; |
| 182 | } |
| 183 | |