| 1 | // -*- C++ -*- |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
| 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_ARRAY |
| 11 | #define _LIBCPP_ARRAY |
| 12 | |
| 13 | /* |
| 14 | array synopsis |
| 15 | |
| 16 | namespace std |
| 17 | { |
| 18 | template <class T, size_t N > |
| 19 | struct array |
| 20 | { |
| 21 | // types: |
| 22 | using value_type = T; |
| 23 | using pointer = T*; |
| 24 | using const_pointer = const T*; |
| 25 | using reference = T&; |
| 26 | using const_reference = const T&; |
| 27 | using size_type = size_t; |
| 28 | using difference_type = ptrdiff_t; |
| 29 | using iterator = implementation-defined; |
| 30 | using const_iterator = implementation-defined; |
| 31 | using reverse_iterator = std::reverse_iterator<iterator>; |
| 32 | using const_reverse_iterator = std::reverse_iterator<const_iterator>; |
| 33 | |
| 34 | // No explicit construct/copy/destroy for aggregate type |
| 35 | void fill(const T& u); // constexpr in C++20 |
| 36 | void swap(array& a) noexcept(is_nothrow_swappable_v<T>); // constexpr in C++20 |
| 37 | |
| 38 | // iterators: |
| 39 | iterator begin() noexcept; // constexpr in C++17 |
| 40 | const_iterator begin() const noexcept; // constexpr in C++17 |
| 41 | iterator end() noexcept; // constexpr in C++17 |
| 42 | const_iterator end() const noexcept; // constexpr in C++17 |
| 43 | |
| 44 | reverse_iterator rbegin() noexcept; // constexpr in C++17 |
| 45 | const_reverse_iterator rbegin() const noexcept; // constexpr in C++17 |
| 46 | reverse_iterator rend() noexcept; // constexpr in C++17 |
| 47 | const_reverse_iterator rend() const noexcept; // constexpr in C++17 |
| 48 | |
| 49 | const_iterator cbegin() const noexcept; // constexpr in C++17 |
| 50 | const_iterator cend() const noexcept; // constexpr in C++17 |
| 51 | const_reverse_iterator crbegin() const noexcept; // constexpr in C++17 |
| 52 | const_reverse_iterator crend() const noexcept; // constexpr in C++17 |
| 53 | |
| 54 | // capacity: |
| 55 | constexpr size_type size() const noexcept; |
| 56 | constexpr size_type max_size() const noexcept; |
| 57 | constexpr bool empty() const noexcept; |
| 58 | |
| 59 | // element access: |
| 60 | reference operator[](size_type n); // constexpr in C++17 |
| 61 | const_reference operator[](size_type n) const; // constexpr in C++14 |
| 62 | reference at(size_type n); // constexpr in C++17 |
| 63 | const_reference at(size_type n) const; // constexpr in C++14 |
| 64 | |
| 65 | reference front(); // constexpr in C++17 |
| 66 | const_reference front() const; // constexpr in C++14 |
| 67 | reference back(); // constexpr in C++17 |
| 68 | const_reference back() const; // constexpr in C++14 |
| 69 | |
| 70 | T* data() noexcept; // constexpr in C++17 |
| 71 | const T* data() const noexcept; // constexpr in C++17 |
| 72 | }; |
| 73 | |
| 74 | template <class T, class... U> |
| 75 | array(T, U...) -> array<T, 1 + sizeof...(U)>; // C++17 |
| 76 | |
| 77 | template <class T, size_t N> |
| 78 | bool operator==(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 |
| 79 | template <class T, size_t N> |
| 80 | bool operator!=(const array<T,N>& x, const array<T,N>& y); // removed in C++20 |
| 81 | template <class T, size_t N> |
| 82 | bool operator<(const array<T,N>& x, const array<T,N>& y); // removed in C++20 |
| 83 | template <class T, size_t N> |
| 84 | bool operator>(const array<T,N>& x, const array<T,N>& y); // removed in C++20 |
| 85 | template <class T, size_t N> |
| 86 | bool operator<=(const array<T,N>& x, const array<T,N>& y); // removed in C++20 |
| 87 | template <class T, size_t N> |
| 88 | bool operator>=(const array<T,N>& x, const array<T,N>& y); // removed in C++20 |
| 89 | template<class T, size_t N> |
| 90 | constexpr synth-three-way-result<T> |
| 91 | operator<=>(const array<T, N>& x, const array<T, N>& y); // since C++20 |
| 92 | |
| 93 | template <class T, size_t N > |
| 94 | void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y))); // constexpr in C++20 |
| 95 | |
| 96 | template <class T, size_t N> |
| 97 | constexpr array<remove_cv_t<T>, N> to_array(T (&a)[N]); // C++20 |
| 98 | template <class T, size_t N> |
| 99 | constexpr array<remove_cv_t<T>, N> to_array(T (&&a)[N]); // C++20 |
| 100 | |
| 101 | template <class T> struct tuple_size; |
| 102 | template <size_t I, class T> struct tuple_element; |
| 103 | template <class T, size_t N> struct tuple_size<array<T, N>>; |
| 104 | template <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>; |
| 105 | template <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14 |
| 106 | template <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++14 |
| 107 | template <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14 |
| 108 | template <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14 |
| 109 | |
| 110 | } // std |
| 111 | |
| 112 | */ |
| 113 | |
| 114 | #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) |
| 115 | # include <__cxx03/array> |
| 116 | #else |
| 117 | # include <__algorithm/equal.h> |
| 118 | # include <__algorithm/fill_n.h> |
| 119 | # include <__algorithm/lexicographical_compare.h> |
| 120 | # include <__algorithm/lexicographical_compare_three_way.h> |
| 121 | # include <__algorithm/swap_ranges.h> |
| 122 | # include <__assert> |
| 123 | # include <__config> |
| 124 | # include <__cstddef/ptrdiff_t.h> |
| 125 | # include <__fwd/array.h> |
| 126 | # include <__iterator/reverse_iterator.h> |
| 127 | # include <__iterator/static_bounded_iter.h> |
| 128 | # include <__iterator/wrap_iter.h> |
| 129 | # include <__tuple/sfinae_helpers.h> |
| 130 | # include <__type_traits/conditional.h> |
| 131 | # include <__type_traits/conjunction.h> |
| 132 | # include <__type_traits/enable_if.h> |
| 133 | # include <__type_traits/is_array.h> |
| 134 | # include <__type_traits/is_const.h> |
| 135 | # include <__type_traits/is_constructible.h> |
| 136 | # include <__type_traits/is_nothrow_constructible.h> |
| 137 | # include <__type_traits/is_relocatable.h> |
| 138 | # include <__type_traits/is_same.h> |
| 139 | # include <__type_traits/is_swappable.h> |
| 140 | # include <__type_traits/remove_cv.h> |
| 141 | # include <__utility/empty.h> |
| 142 | # include <__utility/integer_sequence.h> |
| 143 | # include <__utility/move.h> |
| 144 | # include <__utility/unreachable.h> |
| 145 | # include <stdexcept> |
| 146 | # include <version> |
| 147 | |
| 148 | // standard-mandated includes |
| 149 | |
| 150 | // [iterator.range] |
| 151 | # include <__iterator/access.h> |
| 152 | # include <__iterator/data.h> |
| 153 | # include <__iterator/empty.h> |
| 154 | # include <__iterator/reverse_access.h> |
| 155 | # include <__iterator/size.h> |
| 156 | |
| 157 | // [array.syn] |
| 158 | # include <compare> |
| 159 | # include <initializer_list> |
| 160 | |
| 161 | // [tuple.helper] |
| 162 | # include <__tuple/tuple_element.h> |
| 163 | # include <__tuple/tuple_size.h> |
| 164 | |
| 165 | # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 166 | # pragma GCC system_header |
| 167 | # endif |
| 168 | |
| 169 | _LIBCPP_PUSH_MACROS |
| 170 | # include <__undef_macros> |
| 171 | |
| 172 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 173 | |
| 174 | template <class _Tp, size_t _Size> |
| 175 | struct array { |
| 176 | using __trivially_relocatable _LIBCPP_NODEBUG = __conditional_t<__is_trivially_relocatable_v<_Tp>, array, void>; |
| 177 | |
| 178 | // types: |
| 179 | using __self _LIBCPP_NODEBUG = array; |
| 180 | using value_type = _Tp; |
| 181 | using reference = value_type&; |
| 182 | using const_reference = const value_type&; |
| 183 | using pointer = value_type*; |
| 184 | using const_pointer = const value_type*; |
| 185 | # if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY) |
| 186 | using iterator = __static_bounded_iter<pointer, _Size>; |
| 187 | using const_iterator = __static_bounded_iter<const_pointer, _Size>; |
| 188 | # elif defined(_LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY) |
| 189 | using iterator = __wrap_iter<pointer>; |
| 190 | using const_iterator = __wrap_iter<const_pointer>; |
| 191 | # else |
| 192 | using iterator = pointer; |
| 193 | using const_iterator = const_pointer; |
| 194 | # endif |
| 195 | using size_type = size_t; |
| 196 | using difference_type = ptrdiff_t; |
| 197 | using reverse_iterator = std::reverse_iterator<iterator>; |
| 198 | using const_reverse_iterator = std::reverse_iterator<const_iterator>; |
| 199 | |
| 200 | _Tp __elems_[_Size]; |
| 201 | |
| 202 | // No explicit construct/copy/destroy for aggregate type |
| 203 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void fill(const value_type& __u) { |
| 204 | std::fill_n(data(), _Size, __u); |
| 205 | } |
| 206 | |
| 207 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(array& __a) _NOEXCEPT_(__is_nothrow_swappable_v<_Tp>) { |
| 208 | std::swap_ranges(data(), data() + _Size, __a.data()); |
| 209 | } |
| 210 | |
| 211 | // iterators: |
| 212 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator begin() _NOEXCEPT { |
| 213 | # if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY) |
| 214 | return std::__make_static_bounded_iter<_Size>(data(), data()); |
| 215 | # else |
| 216 | return iterator(data()); |
| 217 | # endif |
| 218 | } |
| 219 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator begin() const _NOEXCEPT { |
| 220 | # if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY) |
| 221 | return std::__make_static_bounded_iter<_Size>(data(), data()); |
| 222 | # else |
| 223 | return const_iterator(data()); |
| 224 | # endif |
| 225 | } |
| 226 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator end() _NOEXCEPT { |
| 227 | # if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY) |
| 228 | return std::__make_static_bounded_iter<_Size>(data() + _Size, data()); |
| 229 | # else |
| 230 | return iterator(data() + _Size); |
| 231 | # endif |
| 232 | } |
| 233 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator end() const _NOEXCEPT { |
| 234 | # if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY) |
| 235 | return std::__make_static_bounded_iter<_Size>(data() + _Size, data()); |
| 236 | # else |
| 237 | return const_iterator(data() + _Size); |
| 238 | # endif |
| 239 | } |
| 240 | |
| 241 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rbegin() _NOEXCEPT { |
| 242 | return reverse_iterator(end()); |
| 243 | } |
| 244 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator |
| 245 | rbegin() const _NOEXCEPT { |
| 246 | return const_reverse_iterator(end()); |
| 247 | } |
| 248 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rend() _NOEXCEPT { |
| 249 | return reverse_iterator(begin()); |
| 250 | } |
| 251 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator rend() const _NOEXCEPT { |
| 252 | return const_reverse_iterator(begin()); |
| 253 | } |
| 254 | |
| 255 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cbegin() const _NOEXCEPT { |
| 256 | return begin(); |
| 257 | } |
| 258 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cend() const _NOEXCEPT { |
| 259 | return end(); |
| 260 | } |
| 261 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator |
| 262 | crbegin() const _NOEXCEPT { |
| 263 | return rbegin(); |
| 264 | } |
| 265 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator crend() const _NOEXCEPT { |
| 266 | return rend(); |
| 267 | } |
| 268 | |
| 269 | // capacity: |
| 270 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT { return _Size; } |
| 271 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT { return _Size; } |
| 272 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT { return _Size == 0; } |
| 273 | |
| 274 | // element access: |
| 275 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference operator[](size_type __n) _NOEXCEPT { |
| 276 | _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < _Size, "out-of-bounds access in std::array<T, N>" ); |
| 277 | return __elems_[__n]; |
| 278 | } |
| 279 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference |
| 280 | operator[](size_type __n) const _NOEXCEPT { |
| 281 | _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < _Size, "out-of-bounds access in std::array<T, N>" ); |
| 282 | return __elems_[__n]; |
| 283 | } |
| 284 | |
| 285 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference at(size_type __n) { |
| 286 | if (__n >= _Size) |
| 287 | std::__throw_out_of_range(msg: "array::at" ); |
| 288 | return __elems_[__n]; |
| 289 | } |
| 290 | |
| 291 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference at(size_type __n) const { |
| 292 | if (__n >= _Size) |
| 293 | std::__throw_out_of_range(msg: "array::at" ); |
| 294 | return __elems_[__n]; |
| 295 | } |
| 296 | |
| 297 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference front() _NOEXCEPT { |
| 298 | return (*this)[0]; |
| 299 | } |
| 300 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference front() const _NOEXCEPT { |
| 301 | return (*this)[0]; |
| 302 | } |
| 303 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference back() _NOEXCEPT { |
| 304 | return (*this)[_Size - 1]; |
| 305 | } |
| 306 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference back() const _NOEXCEPT { |
| 307 | return (*this)[_Size - 1]; |
| 308 | } |
| 309 | |
| 310 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 value_type* data() _NOEXCEPT { |
| 311 | return __elems_; |
| 312 | } |
| 313 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const value_type* data() const _NOEXCEPT { |
| 314 | return __elems_; |
| 315 | } |
| 316 | }; |
| 317 | |
| 318 | template <class _Tp> |
| 319 | struct array<_Tp, 0> { |
| 320 | // types: |
| 321 | using __self _LIBCPP_NODEBUG = array; |
| 322 | using value_type = _Tp; |
| 323 | using reference = value_type&; |
| 324 | using const_reference = const value_type&; |
| 325 | using pointer = value_type*; |
| 326 | using const_pointer = const value_type*; |
| 327 | # if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY) |
| 328 | using iterator = __static_bounded_iter<pointer, 0>; |
| 329 | using const_iterator = __static_bounded_iter<const_pointer, 0>; |
| 330 | # elif defined(_LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY) |
| 331 | using iterator = __wrap_iter<pointer>; |
| 332 | using const_iterator = __wrap_iter<const_pointer>; |
| 333 | # else |
| 334 | using iterator = pointer; |
| 335 | using const_iterator = const_pointer; |
| 336 | # endif |
| 337 | using size_type = size_t; |
| 338 | using difference_type = ptrdiff_t; |
| 339 | using reverse_iterator = std::reverse_iterator<iterator>; |
| 340 | using const_reverse_iterator = std::reverse_iterator<const_iterator>; |
| 341 | |
| 342 | using _EmptyType _LIBCPP_NODEBUG = __conditional_t<is_const<_Tp>::value, const __empty, __empty>; |
| 343 | |
| 344 | struct _ArrayInStructT { |
| 345 | _Tp __data_[1]; |
| 346 | }; |
| 347 | _ALIGNAS_TYPE(_ArrayInStructT) _EmptyType __elems_[sizeof(_ArrayInStructT)]; |
| 348 | |
| 349 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 value_type* data() _NOEXCEPT { return nullptr; } |
| 350 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const value_type* data() const _NOEXCEPT { |
| 351 | return nullptr; |
| 352 | } |
| 353 | |
| 354 | // No explicit construct/copy/destroy for aggregate type |
| 355 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void fill(const value_type&) { |
| 356 | static_assert(!is_const<_Tp>::value, "cannot fill zero-sized array of type 'const T'" ); |
| 357 | } |
| 358 | |
| 359 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(array&) _NOEXCEPT { |
| 360 | static_assert(!is_const<_Tp>::value, "cannot swap zero-sized array of type 'const T'" ); |
| 361 | } |
| 362 | |
| 363 | // iterators: |
| 364 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator begin() _NOEXCEPT { |
| 365 | # if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY) |
| 366 | return std::__make_static_bounded_iter<0>(data(), data()); |
| 367 | # else |
| 368 | return iterator(data()); |
| 369 | # endif |
| 370 | } |
| 371 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator begin() const _NOEXCEPT { |
| 372 | # if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY) |
| 373 | return std::__make_static_bounded_iter<0>(data(), data()); |
| 374 | # else |
| 375 | return const_iterator(data()); |
| 376 | # endif |
| 377 | } |
| 378 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator end() _NOEXCEPT { |
| 379 | # if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY) |
| 380 | return std::__make_static_bounded_iter<0>(data(), data()); |
| 381 | # else |
| 382 | return iterator(data()); |
| 383 | # endif |
| 384 | } |
| 385 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator end() const _NOEXCEPT { |
| 386 | # if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY) |
| 387 | return std::__make_static_bounded_iter<0>(data(), data()); |
| 388 | # else |
| 389 | return const_iterator(data()); |
| 390 | # endif |
| 391 | } |
| 392 | |
| 393 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rbegin() _NOEXCEPT { |
| 394 | return reverse_iterator(end()); |
| 395 | } |
| 396 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator |
| 397 | rbegin() const _NOEXCEPT { |
| 398 | return const_reverse_iterator(end()); |
| 399 | } |
| 400 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rend() _NOEXCEPT { |
| 401 | return reverse_iterator(begin()); |
| 402 | } |
| 403 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator rend() const _NOEXCEPT { |
| 404 | return const_reverse_iterator(begin()); |
| 405 | } |
| 406 | |
| 407 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cbegin() const _NOEXCEPT { |
| 408 | return begin(); |
| 409 | } |
| 410 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cend() const _NOEXCEPT { |
| 411 | return end(); |
| 412 | } |
| 413 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator |
| 414 | crbegin() const _NOEXCEPT { |
| 415 | return rbegin(); |
| 416 | } |
| 417 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator crend() const _NOEXCEPT { |
| 418 | return rend(); |
| 419 | } |
| 420 | |
| 421 | // capacity: |
| 422 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT { return 0; } |
| 423 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT { return 0; } |
| 424 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT { return true; } |
| 425 | |
| 426 | // element access: |
| 427 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference operator[](size_type) _NOEXCEPT { |
| 428 | _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::operator[] on a zero-sized array" ); |
| 429 | __libcpp_unreachable(); |
| 430 | } |
| 431 | |
| 432 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference |
| 433 | operator[](size_type) const _NOEXCEPT { |
| 434 | _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::operator[] on a zero-sized array" ); |
| 435 | __libcpp_unreachable(); |
| 436 | } |
| 437 | |
| 438 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference at(size_type) { |
| 439 | std::__throw_out_of_range(msg: "array<T, 0>::at" ); |
| 440 | __libcpp_unreachable(); |
| 441 | } |
| 442 | |
| 443 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference at(size_type) const { |
| 444 | std::__throw_out_of_range(msg: "array<T, 0>::at" ); |
| 445 | __libcpp_unreachable(); |
| 446 | } |
| 447 | |
| 448 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference front() _NOEXCEPT { |
| 449 | _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::front() on a zero-sized array" ); |
| 450 | __libcpp_unreachable(); |
| 451 | } |
| 452 | |
| 453 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference front() const _NOEXCEPT { |
| 454 | _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::front() on a zero-sized array" ); |
| 455 | __libcpp_unreachable(); |
| 456 | } |
| 457 | |
| 458 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference back() _NOEXCEPT { |
| 459 | _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::back() on a zero-sized array" ); |
| 460 | __libcpp_unreachable(); |
| 461 | } |
| 462 | |
| 463 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference back() const _NOEXCEPT { |
| 464 | _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::back() on a zero-sized array" ); |
| 465 | __libcpp_unreachable(); |
| 466 | } |
| 467 | }; |
| 468 | |
| 469 | # if _LIBCPP_STD_VER >= 17 |
| 470 | template <class _Tp, class... _Args, class = enable_if_t<__all<_IsSame<_Tp, _Args>::value...>::value> > |
| 471 | array(_Tp, _Args...) -> array<_Tp, 1 + sizeof...(_Args)>; |
| 472 | # endif |
| 473 | |
| 474 | template <class _Tp, size_t _Size> |
| 475 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool |
| 476 | operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) { |
| 477 | return std::equal(__x.begin(), __x.end(), __y.begin()); |
| 478 | } |
| 479 | |
| 480 | # if _LIBCPP_STD_VER <= 17 |
| 481 | |
| 482 | template <class _Tp, size_t _Size> |
| 483 | inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) { |
| 484 | return !(__x == __y); |
| 485 | } |
| 486 | |
| 487 | template <class _Tp, size_t _Size> |
| 488 | inline _LIBCPP_HIDE_FROM_ABI bool operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) { |
| 489 | return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); |
| 490 | } |
| 491 | |
| 492 | template <class _Tp, size_t _Size> |
| 493 | inline _LIBCPP_HIDE_FROM_ABI bool operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) { |
| 494 | return __y < __x; |
| 495 | } |
| 496 | |
| 497 | template <class _Tp, size_t _Size> |
| 498 | inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) { |
| 499 | return !(__y < __x); |
| 500 | } |
| 501 | |
| 502 | template <class _Tp, size_t _Size> |
| 503 | inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) { |
| 504 | return !(__x < __y); |
| 505 | } |
| 506 | |
| 507 | # else // _LIBCPP_STD_VER <= 17 |
| 508 | |
| 509 | template <class _Tp, size_t _Size> |
| 510 | _LIBCPP_HIDE_FROM_ABI constexpr __synth_three_way_result<_Tp> |
| 511 | operator<=>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) { |
| 512 | return std::lexicographical_compare_three_way(__x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way); |
| 513 | } |
| 514 | |
| 515 | # endif // _LIBCPP_STD_VER <= 17 |
| 516 | |
| 517 | template <class _Tp, size_t _Size, __enable_if_t<_Size == 0 || __is_swappable_v<_Tp>, int> = 0> |
| 518 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y) |
| 519 | _NOEXCEPT_(noexcept(__x.swap(__y))) { |
| 520 | __x.swap(__y); |
| 521 | } |
| 522 | |
| 523 | template <class _Tp, size_t _Size> |
| 524 | struct tuple_size<array<_Tp, _Size> > : public integral_constant<size_t, _Size> {}; |
| 525 | |
| 526 | template <size_t _Ip, class _Tp, size_t _Size> |
| 527 | struct tuple_element<_Ip, array<_Tp, _Size> > { |
| 528 | static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)" ); |
| 529 | using type _LIBCPP_NODEBUG = _Tp; |
| 530 | }; |
| 531 | |
| 532 | template <size_t _Ip, class _Tp, size_t _Size> |
| 533 | [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp& |
| 534 | get(array<_Tp, _Size>& __a) _NOEXCEPT { |
| 535 | static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)" ); |
| 536 | return __a.__elems_[_Ip]; |
| 537 | } |
| 538 | |
| 539 | template <size_t _Ip, class _Tp, size_t _Size> |
| 540 | [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp& |
| 541 | get(const array<_Tp, _Size>& __a) _NOEXCEPT { |
| 542 | static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)" ); |
| 543 | return __a.__elems_[_Ip]; |
| 544 | } |
| 545 | |
| 546 | template <size_t _Ip, class _Tp, size_t _Size> |
| 547 | [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp&& |
| 548 | get(array<_Tp, _Size>&& __a) _NOEXCEPT { |
| 549 | static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)" ); |
| 550 | return std::move(__a.__elems_[_Ip]); |
| 551 | } |
| 552 | |
| 553 | template <size_t _Ip, class _Tp, size_t _Size> |
| 554 | [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&& |
| 555 | get(const array<_Tp, _Size>&& __a) _NOEXCEPT { |
| 556 | static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)" ); |
| 557 | return std::move(__a.__elems_[_Ip]); |
| 558 | } |
| 559 | |
| 560 | # if _LIBCPP_STD_VER >= 20 |
| 561 | |
| 562 | template <typename _Tp, size_t _Size, size_t... _Index> |
| 563 | _LIBCPP_HIDE_FROM_ABI constexpr array<remove_cv_t<_Tp>, _Size> |
| 564 | __to_array_lvalue_impl(_Tp (&__arr)[_Size], index_sequence<_Index...>) { |
| 565 | return {{__arr[_Index]...}}; |
| 566 | } |
| 567 | |
| 568 | template <typename _Tp, size_t _Size, size_t... _Index> |
| 569 | _LIBCPP_HIDE_FROM_ABI constexpr array<remove_cv_t<_Tp>, _Size> |
| 570 | __to_array_rvalue_impl(_Tp (&&__arr)[_Size], index_sequence<_Index...>) { |
| 571 | return {{std::move(__arr[_Index])...}}; |
| 572 | } |
| 573 | |
| 574 | template <typename _Tp, size_t _Size> |
| 575 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr array<remove_cv_t<_Tp>, _Size> |
| 576 | to_array(_Tp (&__arr)[_Size]) noexcept(is_nothrow_constructible_v<_Tp, _Tp&>) { |
| 577 | static_assert(!is_array_v<_Tp>, "[array.creation]/1: to_array does not accept multidimensional arrays." ); |
| 578 | static_assert(is_constructible_v<_Tp, _Tp&>, "[array.creation]/1: to_array requires copy constructible elements." ); |
| 579 | return std::__to_array_lvalue_impl(__arr, make_index_sequence<_Size>()); |
| 580 | } |
| 581 | |
| 582 | template <typename _Tp, size_t _Size> |
| 583 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr array<remove_cv_t<_Tp>, _Size> |
| 584 | to_array(_Tp (&&__arr)[_Size]) noexcept(is_nothrow_move_constructible_v<_Tp>) { |
| 585 | static_assert(!is_array_v<_Tp>, "[array.creation]/4: to_array does not accept multidimensional arrays." ); |
| 586 | static_assert(is_move_constructible_v<_Tp>, "[array.creation]/4: to_array requires move constructible elements." ); |
| 587 | return std::__to_array_rvalue_impl(std::move(__arr), make_index_sequence<_Size>()); |
| 588 | } |
| 589 | |
| 590 | # endif // _LIBCPP_STD_VER >= 20 |
| 591 | |
| 592 | _LIBCPP_END_NAMESPACE_STD |
| 593 | |
| 594 | _LIBCPP_POP_MACROS |
| 595 | |
| 596 | #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) |
| 597 | |
| 598 | #endif // _LIBCPP_ARRAY |
| 599 | |