2 //===----------------------------------------------------------------------===//
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
8 //===----------------------------------------------------------------------===//
18 template <class T, size_t N >
24 using const_pointer = const 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>;
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
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
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
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
55 constexpr size_type size() const noexcept;
56 constexpr size_type max_size() const noexcept;
57 constexpr bool empty() const noexcept;
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
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
70 T* data() noexcept; // constexpr in C++17
71 const T* data() const noexcept; // constexpr in C++17
74 template <class T, class... U>
75 array(T, U...) -> array<T, 1 + sizeof...(U)>; // C++17
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
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
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
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
114 #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
115 # include <__cxx03/array>
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>
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>
148 // standard-mandated includes
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>
159 # include <initializer_list>
162 # include <__tuple/tuple_element.h>
163 # include <__tuple/tuple_size.h>
165 # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
166 # pragma GCC system_header
170 # include <__undef_macros>
172 _LIBCPP_BEGIN_NAMESPACE_STD
174 template <class _Tp, size_t _Size>
175 struct _LIBCPP_TEMPLATE_VIS array {
176 using __trivially_relocatable = __conditional_t<__libcpp_is_trivially_relocatable<_Tp>::value, array, void>;
179 using __self = 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>;
192 using iterator = pointer;
193 using const_iterator = const_pointer;
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>;
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);
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());
212 _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());
216 return iterator(data());
219 _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());
223 return const_iterator(data());
226 _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());
230 return iterator(data() + _Size);
233 _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());
237 return const_iterator(data() + _Size);
241 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rbegin() _NOEXCEPT {
242 return reverse_iterator(end());
244 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator rbegin() const _NOEXCEPT {
245 return const_reverse_iterator(end());
247 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rend() _NOEXCEPT {
248 return reverse_iterator(begin());
250 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator rend() const _NOEXCEPT {
251 return const_reverse_iterator(begin());
254 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cbegin() const _NOEXCEPT { return begin(); }
255 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cend() const _NOEXCEPT { return end(); }
256 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator crbegin() const _NOEXCEPT {
259 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
262 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT { return _Size; }
263 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT { return _Size; }
264 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT { return _Size == 0; }
267 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference operator[](size_type __n) _NOEXCEPT {
268 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < _Size, "out-of-bounds access in std::array<T, N>");
269 return __elems_[__n];
271 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference operator[](size_type __n) const _NOEXCEPT {
272 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < _Size, "out-of-bounds access in std::array<T, N>");
273 return __elems_[__n];
276 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference at(size_type __n) {
278 __throw_out_of_range("array::at");
279 return __elems_[__n];
282 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference at(size_type __n) const {
284 __throw_out_of_range("array::at");
285 return __elems_[__n];
288 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference front() _NOEXCEPT { return (*this)[0]; }
289 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference front() const _NOEXCEPT { return (*this)[0]; }
290 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference back() _NOEXCEPT { return (*this)[_Size - 1]; }
291 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference back() const _NOEXCEPT {
292 return (*this)[_Size - 1];
295 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 value_type* data() _NOEXCEPT { return __elems_; }
296 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const value_type* data() const _NOEXCEPT { return __elems_; }
300 struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0> {
302 using __self = array;
303 using value_type = _Tp;
304 using reference = value_type&;
305 using const_reference = const value_type&;
306 using pointer = value_type*;
307 using const_pointer = const value_type*;
308 # if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
309 using iterator = __static_bounded_iter<pointer, 0>;
310 using const_iterator = __static_bounded_iter<const_pointer, 0>;
311 # elif defined(_LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY)
312 using iterator = __wrap_iter<pointer>;
313 using const_iterator = __wrap_iter<const_pointer>;
315 using iterator = pointer;
316 using const_iterator = const_pointer;
318 using size_type = size_t;
319 using difference_type = ptrdiff_t;
320 using reverse_iterator = std::reverse_iterator<iterator>;
321 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
323 using _EmptyType = __conditional_t<is_const<_Tp>::value, const __empty, __empty>;
325 struct _ArrayInStructT {
328 _ALIGNAS_TYPE(_ArrayInStructT) _EmptyType __elems_[sizeof(_ArrayInStructT)];
330 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 value_type* data() _NOEXCEPT { return nullptr; }
331 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const value_type* data() const _NOEXCEPT { return nullptr; }
333 // No explicit construct/copy/destroy for aggregate type
334 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void fill(const value_type&) {
335 static_assert(!is_const<_Tp>::value, "cannot fill zero-sized array of type 'const T'");
338 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(array&) _NOEXCEPT {
339 static_assert(!is_const<_Tp>::value, "cannot swap zero-sized array of type 'const T'");
343 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator begin() _NOEXCEPT {
344 # if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
345 return std::__make_static_bounded_iter<0>(data(), data());
347 return iterator(data());
350 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator begin() const _NOEXCEPT {
351 # if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
352 return std::__make_static_bounded_iter<0>(data(), data());
354 return const_iterator(data());
357 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator end() _NOEXCEPT {
358 # if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
359 return std::__make_static_bounded_iter<0>(data(), data());
361 return iterator(data());
364 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator end() const _NOEXCEPT {
365 # if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
366 return std::__make_static_bounded_iter<0>(data(), data());
368 return const_iterator(data());
372 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rbegin() _NOEXCEPT {
373 return reverse_iterator(end());
375 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator rbegin() const _NOEXCEPT {
376 return const_reverse_iterator(end());
378 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rend() _NOEXCEPT {
379 return reverse_iterator(begin());
381 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator rend() const _NOEXCEPT {
382 return const_reverse_iterator(begin());
385 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cbegin() const _NOEXCEPT { return begin(); }
386 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cend() const _NOEXCEPT { return end(); }
387 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator crbegin() const _NOEXCEPT {
390 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
393 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT { return 0; }
394 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT { return 0; }
395 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT { return true; }
398 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference operator[](size_type) _NOEXCEPT {
399 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
400 __libcpp_unreachable();
403 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference operator[](size_type) const _NOEXCEPT {
404 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
405 __libcpp_unreachable();
408 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference at(size_type) {
409 __throw_out_of_range("array<T, 0>::at");
410 __libcpp_unreachable();
413 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference at(size_type) const {
414 __throw_out_of_range("array<T, 0>::at");
415 __libcpp_unreachable();
418 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference front() _NOEXCEPT {
419 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::front() on a zero-sized array");
420 __libcpp_unreachable();
423 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference front() const _NOEXCEPT {
424 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::front() on a zero-sized array");
425 __libcpp_unreachable();
428 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference back() _NOEXCEPT {
429 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::back() on a zero-sized array");
430 __libcpp_unreachable();
433 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference back() const _NOEXCEPT {
434 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::back() on a zero-sized array");
435 __libcpp_unreachable();
439 # if _LIBCPP_STD_VER >= 17
440 template <class _Tp, class... _Args, class = enable_if_t<__all<_IsSame<_Tp, _Args>::value...>::value> >
441 array(_Tp, _Args...) -> array<_Tp, 1 + sizeof...(_Args)>;
444 template <class _Tp, size_t _Size>
445 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
446 operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
447 return std::equal(__x.begin(), __x.end(), __y.begin());
450 # if _LIBCPP_STD_VER <= 17
452 template <class _Tp, size_t _Size>
453 inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
454 return !(__x == __y);
457 template <class _Tp, size_t _Size>
458 inline _LIBCPP_HIDE_FROM_ABI bool operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
459 return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
462 template <class _Tp, size_t _Size>
463 inline _LIBCPP_HIDE_FROM_ABI bool operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
467 template <class _Tp, size_t _Size>
468 inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
472 template <class _Tp, size_t _Size>
473 inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
477 # else // _LIBCPP_STD_VER <= 17
479 template <class _Tp, size_t _Size>
480 _LIBCPP_HIDE_FROM_ABI constexpr __synth_three_way_result<_Tp>
481 operator<=>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
482 return std::lexicographical_compare_three_way(__x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);
485 # endif // _LIBCPP_STD_VER <= 17
487 template <class _Tp, size_t _Size, __enable_if_t<_Size == 0 || __is_swappable_v<_Tp>, int> = 0>
488 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y)
489 _NOEXCEPT_(noexcept(__x.swap(__y))) {
493 template <class _Tp, size_t _Size>
494 struct _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> > : public integral_constant<size_t, _Size> {};
496 template <size_t _Ip, class _Tp, size_t _Size>
497 struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> > {
498 static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)");
502 template <size_t _Ip, class _Tp, size_t _Size>
503 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp& get(array<_Tp, _Size>& __a) _NOEXCEPT {
504 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)");
505 return __a.__elems_[_Ip];
508 template <size_t _Ip, class _Tp, size_t _Size>
509 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp& get(const array<_Tp, _Size>& __a) _NOEXCEPT {
510 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)");
511 return __a.__elems_[_Ip];
514 template <size_t _Ip, class _Tp, size_t _Size>
515 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp&& get(array<_Tp, _Size>&& __a) _NOEXCEPT {
516 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)");
517 return std::move(__a.__elems_[_Ip]);
520 template <size_t _Ip, class _Tp, size_t _Size>
521 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&& get(const array<_Tp, _Size>&& __a) _NOEXCEPT {
522 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)");
523 return std::move(__a.__elems_[_Ip]);
526 # if _LIBCPP_STD_VER >= 20
528 template <typename _Tp, size_t _Size, size_t... _Index>
529 _LIBCPP_HIDE_FROM_ABI constexpr array<remove_cv_t<_Tp>, _Size>
530 __to_array_lvalue_impl(_Tp (&__arr)[_Size], index_sequence<_Index...>) {
531 return {{__arr[_Index]...}};
534 template <typename _Tp, size_t _Size, size_t... _Index>
535 _LIBCPP_HIDE_FROM_ABI constexpr array<remove_cv_t<_Tp>, _Size>
536 __to_array_rvalue_impl(_Tp (&&__arr)[_Size], index_sequence<_Index...>) {
537 return {{std::move(__arr[_Index])...}};
540 template <typename _Tp, size_t _Size>
541 _LIBCPP_HIDE_FROM_ABI constexpr array<remove_cv_t<_Tp>, _Size>
542 to_array(_Tp (&__arr)[_Size]) noexcept(is_nothrow_constructible_v<_Tp, _Tp&>) {
543 static_assert(!is_array_v<_Tp>, "[array.creation]/1: to_array does not accept multidimensional arrays.");
544 static_assert(is_constructible_v<_Tp, _Tp&>, "[array.creation]/1: to_array requires copy constructible elements.");
545 return std::__to_array_lvalue_impl(__arr, make_index_sequence<_Size>());
548 template <typename _Tp, size_t _Size>
549 _LIBCPP_HIDE_FROM_ABI constexpr array<remove_cv_t<_Tp>, _Size>
550 to_array(_Tp (&&__arr)[_Size]) noexcept(is_nothrow_move_constructible_v<_Tp>) {
551 static_assert(!is_array_v<_Tp>, "[array.creation]/4: to_array does not accept multidimensional arrays.");
552 static_assert(is_move_constructible_v<_Tp>, "[array.creation]/4: to_array requires move constructible elements.");
553 return std::__to_array_rvalue_impl(std::move(__arr), make_index_sequence<_Size>());
556 # endif // _LIBCPP_STD_VER >= 20
558 _LIBCPP_END_NAMESPACE_STD
562 # if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
563 # include <algorithm>
568 # include <type_traits>
571 #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
573 #endif // _LIBCPP_ARRAY