|
| 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 | +# In addition to being available via inclusion of the <iterator> header, |
| 10 | +# the function templates in [iterator.range] are available when any of the following |
| 11 | +# headers are included: <array>, <deque>, <flat_map>, <flat_set>, <forward_list>, |
| 12 | +# <list>, <map>, <regex>, <set>, <span>, <string>, <string_view>, <unordered_map>, |
| 13 | +# <unordered_set>, <vector>. |
| 14 | + |
| 15 | +# RUN: %{python} %s %{libcxx-dir}/utils |
| 16 | +# END. |
| 17 | + |
| 18 | +import sys |
| 19 | + |
| 20 | +sys.path.append(sys.argv[1]) |
| 21 | +from libcxx.header_information import ( |
| 22 | + lit_header_restrictions, |
| 23 | + lit_header_undeprecations, |
| 24 | + Header, |
| 25 | +) |
| 26 | + |
| 27 | +headers = list( |
| 28 | + map( |
| 29 | + Header, |
| 30 | + [ |
| 31 | + "array", |
| 32 | + "deque", |
| 33 | + "flat_map", |
| 34 | + "flat_set", |
| 35 | + "forward_list", |
| 36 | + "list", |
| 37 | + "map", |
| 38 | + "regex", |
| 39 | + "set", |
| 40 | + "span", |
| 41 | + "string", |
| 42 | + "string_view", |
| 43 | + "unordered_map", |
| 44 | + "unordered_set", |
| 45 | + "vector", |
| 46 | + ], |
| 47 | + ) |
| 48 | +) |
| 49 | + |
| 50 | +for header in headers: |
| 51 | + print( |
| 52 | + f"""\ |
| 53 | +//--- {header}.pass.cpp |
| 54 | +{lit_header_restrictions.get(header, '')} |
| 55 | +{lit_header_undeprecations.get(header, '')} |
| 56 | +// UNSUPPORTED: c++03 |
| 57 | +
|
| 58 | +#include <{header}> |
| 59 | +#include <cassert> |
| 60 | +#include <initializer_list> |
| 61 | +
|
| 62 | +#include "test_macros.h" |
| 63 | +
|
| 64 | +struct Container {{ |
| 65 | + int a[3] = {{1, 2, 3}}; |
| 66 | +
|
| 67 | + int* begin() {{ return &a[0]; }} |
| 68 | + const int* begin() const {{ return &a[0]; }} |
| 69 | + int* rbegin() {{ return &a[2]; }} |
| 70 | + const int* rbegin() const {{ return &a[2]; }} |
| 71 | + int* end() {{ return &a[3]; }} |
| 72 | + const int* end() const {{ return &a[3]; }} |
| 73 | + int* rend() {{ return (&a[0]) - 1; }} |
| 74 | + const int* rend() const {{ return (&a[0]) - 1; }} |
| 75 | + std::size_t size() const {{ return 3; }} |
| 76 | + bool empty() const {{ return false; }} |
| 77 | + int* data() {{return &a[0]; }} |
| 78 | + const int* data() const {{ return &a[0]; }} |
| 79 | +}}; |
| 80 | +
|
| 81 | +int main(int, char**) {{ |
| 82 | + {{ |
| 83 | + Container c; |
| 84 | + const auto& cc = c; |
| 85 | + assert(std::begin(c) == c.begin()); |
| 86 | + assert(std::begin(cc) == cc.begin()); |
| 87 | + assert(std::end(c) == c.end()); |
| 88 | + assert(std::end(cc) == cc.end()); |
| 89 | +#if TEST_STD_VER >= 14 |
| 90 | + assert(std::cbegin(c) == cc.begin()); |
| 91 | + assert(std::cbegin(cc) == cc.begin()); |
| 92 | + assert(std::cend(c) == cc.end()); |
| 93 | + assert(std::cend(cc) == cc.end()); |
| 94 | + assert(std::rbegin(c) == c.rbegin()); |
| 95 | + assert(std::rbegin(cc) == cc.rbegin()); |
| 96 | + assert(std::rend(c) == cc.rend()); |
| 97 | + assert(std::rend(cc) == cc.rend()); |
| 98 | + assert(std::crbegin(c) == cc.rbegin()); |
| 99 | + assert(std::crbegin(cc) == cc.rbegin()); |
| 100 | + assert(std::crend(c) == cc.rend()); |
| 101 | + assert(std::crend(cc) == cc.rend()); |
| 102 | +#endif |
| 103 | +#if TEST_STD_VER >= 17 |
| 104 | + assert(std::data(c) == c.data()); |
| 105 | + assert(std::data(cc) == cc.data()); |
| 106 | + assert(std::size(cc) == cc.size()); |
| 107 | + assert(std::empty(cc) == cc.empty()); |
| 108 | +#endif |
| 109 | +#if TEST_STD_VER >= 20 |
| 110 | + assert(std::ssize(cc) == 3); |
| 111 | +#endif |
| 112 | + }} |
| 113 | + {{ |
| 114 | + int a[] = {{1, 2, 3}}; |
| 115 | + const auto& ca = a; |
| 116 | + assert(std::begin(a) == &a[0]); |
| 117 | + assert(std::begin(ca) == &ca[0]); |
| 118 | + assert(std::end(a) == &a[3]); |
| 119 | + assert(std::end(ca) == &ca[3]); |
| 120 | +#if TEST_STD_VER >= 14 |
| 121 | + assert(std::cbegin(a) == &a[0]); |
| 122 | + assert(std::cbegin(ca) == &ca[0]); |
| 123 | + assert(std::cend(a) == &a[3]); |
| 124 | + assert(std::cend(ca) == &ca[3]); |
| 125 | + assert(std::rbegin(a) == std::reverse_iterator<int*>(std::end(a))); |
| 126 | + assert(std::rbegin(ca) == std::reverse_iterator<const int*>(std::end(ca))); |
| 127 | + assert(std::rend(a) == std::reverse_iterator<int*>(std::begin(a))); |
| 128 | + assert(std::rend(ca) == std::reverse_iterator<const int*>(std::begin(ca))); |
| 129 | + assert(std::crbegin(a) == std::reverse_iterator<const int*>(std::end(a))); |
| 130 | + assert(std::crbegin(ca) == std::reverse_iterator<const int*>(std::end(ca))); |
| 131 | + assert(std::crend(a) == std::reverse_iterator<const int*>(std::begin(a))); |
| 132 | + assert(std::crend(ca) == std::reverse_iterator<const int*>(std::begin(ca))); |
| 133 | +#endif |
| 134 | +#if TEST_STD_VER >= 17 |
| 135 | + assert(std::size(ca) == 3); |
| 136 | + assert(!std::empty(ca)); |
| 137 | + assert(std::data(a) == &a[0]); |
| 138 | + assert(std::data(ca) == &ca[0]); |
| 139 | +#endif |
| 140 | +#if TEST_STD_VER >= 20 |
| 141 | + assert(std::ssize(ca) == 3); |
| 142 | +#endif |
| 143 | + }} |
| 144 | + {{ |
| 145 | + auto il = {{1, 2, 3}}; |
| 146 | + const auto& cil = il; |
| 147 | + assert(std::begin(il) == il.begin()); |
| 148 | + assert(std::begin(cil) == cil.begin()); |
| 149 | + assert(std::end(il) == il.end()); |
| 150 | + assert(std::end(cil) == cil.end()); |
| 151 | +#if TEST_STD_VER >= 14 |
| 152 | + assert(std::cbegin(il) == cil.begin()); |
| 153 | + assert(std::cbegin(cil) == cil.begin()); |
| 154 | + assert(std::cend(il) == cil.end()); |
| 155 | + assert(std::cend(cil) == cil.end()); |
| 156 | + assert(std::rbegin(il) == std::reverse_iterator<const int*>(std::end(il))); |
| 157 | + assert(std::rbegin(cil) == std::reverse_iterator<const int*>(std::end(il))); |
| 158 | + assert(std::rend(il) == std::reverse_iterator<const int*>(std::begin(il))); |
| 159 | + assert(std::rend(cil) == std::reverse_iterator<const int*>(std::begin(il))); |
| 160 | + assert(std::crbegin(il) == std::reverse_iterator<const int*>(std::end(il))); |
| 161 | + assert(std::crbegin(cil) == std::reverse_iterator<const int*>(std::end(il))); |
| 162 | + assert(std::crend(il) == std::reverse_iterator<const int*>(std::begin(il))); |
| 163 | + assert(std::crend(cil) == std::reverse_iterator<const int*>(std::begin(il))); |
| 164 | +#endif |
| 165 | +#if TEST_STD_VER >= 17 |
| 166 | + assert(std::size(cil) == 3); |
| 167 | + assert(!std::empty(cil)); |
| 168 | + assert(std::data(il) == &*std::begin(il)); |
| 169 | + assert(std::data(cil) == &*std::begin(il)); |
| 170 | +#endif |
| 171 | +#if TEST_STD_VER >= 20 |
| 172 | + assert(std::ssize(cil) == 3); |
| 173 | +#endif |
| 174 | + }} |
| 175 | +
|
| 176 | + return 0; |
| 177 | +}} |
| 178 | +
|
| 179 | +""" |
| 180 | + ) |
0 commit comments