610 lines · plain
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-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCPP_ARRAY11#define _LIBCPP_ARRAY12 13/*14 array synopsis15 16namespace std17{18template <class T, size_t N >19struct array20{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 type35 void fill(const T& u); // constexpr in C++2036 void swap(array& a) noexcept(is_nothrow_swappable_v<T>); // constexpr in C++2037 38 // iterators:39 iterator begin() noexcept; // constexpr in C++1740 const_iterator begin() const noexcept; // constexpr in C++1741 iterator end() noexcept; // constexpr in C++1742 const_iterator end() const noexcept; // constexpr in C++1743 44 reverse_iterator rbegin() noexcept; // constexpr in C++1745 const_reverse_iterator rbegin() const noexcept; // constexpr in C++1746 reverse_iterator rend() noexcept; // constexpr in C++1747 const_reverse_iterator rend() const noexcept; // constexpr in C++1748 49 const_iterator cbegin() const noexcept; // constexpr in C++1750 const_iterator cend() const noexcept; // constexpr in C++1751 const_reverse_iterator crbegin() const noexcept; // constexpr in C++1752 const_reverse_iterator crend() const noexcept; // constexpr in C++1753 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++1761 const_reference operator[](size_type n) const; // constexpr in C++1462 reference at(size_type n); // constexpr in C++1763 const_reference at(size_type n) const; // constexpr in C++1464 65 reference front(); // constexpr in C++1766 const_reference front() const; // constexpr in C++1467 reference back(); // constexpr in C++1768 const_reference back() const; // constexpr in C++1469 70 T* data() noexcept; // constexpr in C++1771 const T* data() const noexcept; // constexpr in C++1772};73 74template <class T, class... U>75 array(T, U...) -> array<T, 1 + sizeof...(U)>; // C++1776 77template <class T, size_t N>78 bool operator==(const array<T,N>& x, const array<T,N>& y); // constexpr in C++2079template <class T, size_t N>80 bool operator!=(const array<T,N>& x, const array<T,N>& y); // removed in C++2081template <class T, size_t N>82 bool operator<(const array<T,N>& x, const array<T,N>& y); // removed in C++2083template <class T, size_t N>84 bool operator>(const array<T,N>& x, const array<T,N>& y); // removed in C++2085template <class T, size_t N>86 bool operator<=(const array<T,N>& x, const array<T,N>& y); // removed in C++2087template <class T, size_t N>88 bool operator>=(const array<T,N>& x, const array<T,N>& y); // removed in C++2089template<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++2092 93template <class T, size_t N >94 void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y))); // constexpr in C++2095 96template <class T, size_t N>97 constexpr array<remove_cv_t<T>, N> to_array(T (&a)[N]); // C++2098template <class T, size_t N>99 constexpr array<remove_cv_t<T>, N> to_array(T (&&a)[N]); // C++20100 101template <class T> struct tuple_size;102template <size_t I, class T> struct tuple_element;103template <class T, size_t N> struct tuple_size<array<T, N>>;104template <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>;105template <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14106template <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++14107template <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14108template <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14109 110} // std111 112*/113 114#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)115# include <__cxx03/array>116#else117# 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_same.h>138# include <__type_traits/is_swappable.h>139# include <__type_traits/is_trivially_relocatable.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 includes149 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_header167# endif168 169_LIBCPP_PUSH_MACROS170# include <__undef_macros>171 172_LIBCPP_BEGIN_NAMESPACE_STD173 174template <class _Tp, size_t _Size>175struct array {176 using __trivially_relocatable _LIBCPP_NODEBUG =177 __conditional_t<__libcpp_is_trivially_relocatable<_Tp>::value, array, void>;178 179 // types:180 using __self _LIBCPP_NODEBUG = array;181 using value_type = _Tp;182 using reference = value_type&;183 using const_reference = const value_type&;184 using pointer = value_type*;185 using const_pointer = const value_type*;186# if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)187 using iterator = __static_bounded_iter<pointer, _Size>;188 using const_iterator = __static_bounded_iter<const_pointer, _Size>;189# elif defined(_LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY)190 using iterator = __wrap_iter<pointer>;191 using const_iterator = __wrap_iter<const_pointer>;192# else193 using iterator = pointer;194 using const_iterator = const_pointer;195# endif196 using size_type = size_t;197 using difference_type = ptrdiff_t;198 using reverse_iterator = std::reverse_iterator<iterator>;199 using const_reverse_iterator = std::reverse_iterator<const_iterator>;200 201 _Tp __elems_[_Size];202 203 // No explicit construct/copy/destroy for aggregate type204 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void fill(const value_type& __u) {205 std::fill_n(data(), _Size, __u);206 }207 208 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(array& __a) _NOEXCEPT_(__is_nothrow_swappable_v<_Tp>) {209 std::swap_ranges(data(), data() + _Size, __a.data());210 }211 212 // iterators:213 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator begin() _NOEXCEPT {214# if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)215 return std::__make_static_bounded_iter<_Size>(data(), data());216# else217 return iterator(data());218# endif219 }220 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator begin() const _NOEXCEPT {221# if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)222 return std::__make_static_bounded_iter<_Size>(data(), data());223# else224 return const_iterator(data());225# endif226 }227 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator end() _NOEXCEPT {228# if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)229 return std::__make_static_bounded_iter<_Size>(data() + _Size, data());230# else231 return iterator(data() + _Size);232# endif233 }234 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator end() const _NOEXCEPT {235# if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)236 return std::__make_static_bounded_iter<_Size>(data() + _Size, data());237# else238 return const_iterator(data() + _Size);239# endif240 }241 242 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rbegin() _NOEXCEPT {243 return reverse_iterator(end());244 }245 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator246 rbegin() const _NOEXCEPT {247 return const_reverse_iterator(end());248 }249 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rend() _NOEXCEPT {250 return reverse_iterator(begin());251 }252 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator rend() const _NOEXCEPT {253 return const_reverse_iterator(begin());254 }255 256 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cbegin() const _NOEXCEPT {257 return begin();258 }259 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cend() const _NOEXCEPT {260 return end();261 }262 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator263 crbegin() const _NOEXCEPT {264 return rbegin();265 }266 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator crend() const _NOEXCEPT {267 return rend();268 }269 270 // capacity:271 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT { return _Size; }272 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT { return _Size; }273 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT { return _Size == 0; }274 275 // element access:276 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference operator[](size_type __n) _NOEXCEPT {277 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < _Size, "out-of-bounds access in std::array<T, N>");278 return __elems_[__n];279 }280 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference281 operator[](size_type __n) const _NOEXCEPT {282 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < _Size, "out-of-bounds access in std::array<T, N>");283 return __elems_[__n];284 }285 286 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference at(size_type __n) {287 if (__n >= _Size)288 std::__throw_out_of_range("array::at");289 return __elems_[__n];290 }291 292 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference at(size_type __n) const {293 if (__n >= _Size)294 std::__throw_out_of_range("array::at");295 return __elems_[__n];296 }297 298 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference front() _NOEXCEPT {299 return (*this)[0];300 }301 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference front() const _NOEXCEPT {302 return (*this)[0];303 }304 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference back() _NOEXCEPT {305 return (*this)[_Size - 1];306 }307 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference back() const _NOEXCEPT {308 return (*this)[_Size - 1];309 }310 311 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 value_type* data() _NOEXCEPT {312 return __elems_;313 }314 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const value_type* data() const _NOEXCEPT {315 return __elems_;316 }317};318 319template <class _Tp>320struct array<_Tp, 0> {321 // types:322 using __self _LIBCPP_NODEBUG = array;323 using value_type = _Tp;324 using reference = value_type&;325 using const_reference = const value_type&;326 using pointer = value_type*;327 using const_pointer = const value_type*;328# if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)329 using iterator = __static_bounded_iter<pointer, 0>;330 using const_iterator = __static_bounded_iter<const_pointer, 0>;331# elif defined(_LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY)332 using iterator = __wrap_iter<pointer>;333 using const_iterator = __wrap_iter<const_pointer>;334# else335 using iterator = pointer;336 using const_iterator = const_pointer;337# endif338 using size_type = size_t;339 using difference_type = ptrdiff_t;340 using reverse_iterator = std::reverse_iterator<iterator>;341 using const_reverse_iterator = std::reverse_iterator<const_iterator>;342 343 using _EmptyType _LIBCPP_NODEBUG = __conditional_t<is_const<_Tp>::value, const __empty, __empty>;344 345 struct _ArrayInStructT {346 _Tp __data_[1];347 };348 _ALIGNAS_TYPE(_ArrayInStructT) _EmptyType __elems_[sizeof(_ArrayInStructT)];349 350 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 value_type* data() _NOEXCEPT { return nullptr; }351 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const value_type* data() const _NOEXCEPT {352 return nullptr;353 }354 355 // No explicit construct/copy/destroy for aggregate type356 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void fill(const value_type&) {357 static_assert(!is_const<_Tp>::value, "cannot fill zero-sized array of type 'const T'");358 }359 360 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(array&) _NOEXCEPT {361 static_assert(!is_const<_Tp>::value, "cannot swap zero-sized array of type 'const T'");362 }363 364 // iterators:365 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator begin() _NOEXCEPT {366# if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)367 return std::__make_static_bounded_iter<0>(data(), data());368# else369 return iterator(data());370# endif371 }372 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator begin() const _NOEXCEPT {373# if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)374 return std::__make_static_bounded_iter<0>(data(), data());375# else376 return const_iterator(data());377# endif378 }379 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator end() _NOEXCEPT {380# if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)381 return std::__make_static_bounded_iter<0>(data(), data());382# else383 return iterator(data());384# endif385 }386 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator end() const _NOEXCEPT {387# if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)388 return std::__make_static_bounded_iter<0>(data(), data());389# else390 return const_iterator(data());391# endif392 }393 394 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rbegin() _NOEXCEPT {395 return reverse_iterator(end());396 }397 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator398 rbegin() const _NOEXCEPT {399 return const_reverse_iterator(end());400 }401 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rend() _NOEXCEPT {402 return reverse_iterator(begin());403 }404 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator rend() const _NOEXCEPT {405 return const_reverse_iterator(begin());406 }407 408 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cbegin() const _NOEXCEPT {409 return begin();410 }411 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cend() const _NOEXCEPT {412 return end();413 }414 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator415 crbegin() const _NOEXCEPT {416 return rbegin();417 }418 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator crend() const _NOEXCEPT {419 return rend();420 }421 422 // capacity:423 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT { return 0; }424 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT { return 0; }425 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT { return true; }426 427 // element access:428 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference operator[](size_type) _NOEXCEPT {429 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::operator[] on a zero-sized array");430 __libcpp_unreachable();431 }432 433 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference434 operator[](size_type) const _NOEXCEPT {435 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::operator[] on a zero-sized array");436 __libcpp_unreachable();437 }438 439 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference at(size_type) {440 std::__throw_out_of_range("array<T, 0>::at");441 __libcpp_unreachable();442 }443 444 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference at(size_type) const {445 std::__throw_out_of_range("array<T, 0>::at");446 __libcpp_unreachable();447 }448 449 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference front() _NOEXCEPT {450 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::front() on a zero-sized array");451 __libcpp_unreachable();452 }453 454 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference front() const _NOEXCEPT {455 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::front() on a zero-sized array");456 __libcpp_unreachable();457 }458 459 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference back() _NOEXCEPT {460 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::back() on a zero-sized array");461 __libcpp_unreachable();462 }463 464 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference back() const _NOEXCEPT {465 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::back() on a zero-sized array");466 __libcpp_unreachable();467 }468};469 470# if _LIBCPP_STD_VER >= 17471template <class _Tp, class... _Args, class = enable_if_t<__all<_IsSame<_Tp, _Args>::value...>::value> >472array(_Tp, _Args...) -> array<_Tp, 1 + sizeof...(_Args)>;473# endif474 475template <class _Tp, size_t _Size>476inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool477operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {478 return std::equal(__x.begin(), __x.end(), __y.begin());479}480 481# if _LIBCPP_STD_VER <= 17482 483template <class _Tp, size_t _Size>484inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {485 return !(__x == __y);486}487 488template <class _Tp, size_t _Size>489inline _LIBCPP_HIDE_FROM_ABI bool operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {490 return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());491}492 493template <class _Tp, size_t _Size>494inline _LIBCPP_HIDE_FROM_ABI bool operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {495 return __y < __x;496}497 498template <class _Tp, size_t _Size>499inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {500 return !(__y < __x);501}502 503template <class _Tp, size_t _Size>504inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {505 return !(__x < __y);506}507 508# else // _LIBCPP_STD_VER <= 17509 510template <class _Tp, size_t _Size>511_LIBCPP_HIDE_FROM_ABI constexpr __synth_three_way_result<_Tp>512operator<=>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {513 return std::lexicographical_compare_three_way(__x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);514}515 516# endif // _LIBCPP_STD_VER <= 17517 518template <class _Tp, size_t _Size, __enable_if_t<_Size == 0 || __is_swappable_v<_Tp>, int> = 0>519inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y)520 _NOEXCEPT_(noexcept(__x.swap(__y))) {521 __x.swap(__y);522}523 524template <class _Tp, size_t _Size>525struct tuple_size<array<_Tp, _Size> > : public integral_constant<size_t, _Size> {};526 527template <size_t _Ip, class _Tp, size_t _Size>528struct tuple_element<_Ip, array<_Tp, _Size> > {529 static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)");530 using type _LIBCPP_NODEBUG = _Tp;531};532 533template <size_t _Ip, class _Tp, size_t _Size>534[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp&535get(array<_Tp, _Size>& __a) _NOEXCEPT {536 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)");537 return __a.__elems_[_Ip];538}539 540template <size_t _Ip, class _Tp, size_t _Size>541[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&542get(const array<_Tp, _Size>& __a) _NOEXCEPT {543 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)");544 return __a.__elems_[_Ip];545}546 547template <size_t _Ip, class _Tp, size_t _Size>548[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp&&549get(array<_Tp, _Size>&& __a) _NOEXCEPT {550 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)");551 return std::move(__a.__elems_[_Ip]);552}553 554template <size_t _Ip, class _Tp, size_t _Size>555[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&&556get(const array<_Tp, _Size>&& __a) _NOEXCEPT {557 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)");558 return std::move(__a.__elems_[_Ip]);559}560 561# if _LIBCPP_STD_VER >= 20562 563template <typename _Tp, size_t _Size, size_t... _Index>564_LIBCPP_HIDE_FROM_ABI constexpr array<remove_cv_t<_Tp>, _Size>565__to_array_lvalue_impl(_Tp (&__arr)[_Size], index_sequence<_Index...>) {566 return {{__arr[_Index]...}};567}568 569template <typename _Tp, size_t _Size, size_t... _Index>570_LIBCPP_HIDE_FROM_ABI constexpr array<remove_cv_t<_Tp>, _Size>571__to_array_rvalue_impl(_Tp (&&__arr)[_Size], index_sequence<_Index...>) {572 return {{std::move(__arr[_Index])...}};573}574 575template <typename _Tp, size_t _Size>576[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr array<remove_cv_t<_Tp>, _Size>577to_array(_Tp (&__arr)[_Size]) noexcept(is_nothrow_constructible_v<_Tp, _Tp&>) {578 static_assert(!is_array_v<_Tp>, "[array.creation]/1: to_array does not accept multidimensional arrays.");579 static_assert(is_constructible_v<_Tp, _Tp&>, "[array.creation]/1: to_array requires copy constructible elements.");580 return std::__to_array_lvalue_impl(__arr, make_index_sequence<_Size>());581}582 583template <typename _Tp, size_t _Size>584[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr array<remove_cv_t<_Tp>, _Size>585to_array(_Tp (&&__arr)[_Size]) noexcept(is_nothrow_move_constructible_v<_Tp>) {586 static_assert(!is_array_v<_Tp>, "[array.creation]/4: to_array does not accept multidimensional arrays.");587 static_assert(is_move_constructible_v<_Tp>, "[array.creation]/4: to_array requires move constructible elements.");588 return std::__to_array_rvalue_impl(std::move(__arr), make_index_sequence<_Size>());589}590 591# endif // _LIBCPP_STD_VER >= 20592 593_LIBCPP_END_NAMESPACE_STD594 595_LIBCPP_POP_MACROS596 597# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20598# include <algorithm>599# include <concepts>600# include <cstdlib>601# include <iterator>602# include <new>603# include <optional>604# include <type_traits>605# include <utility>606# endif607#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)608 609#endif // _LIBCPP_ARRAY610