• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
16namespace std
17{
18template <class T, size_t N >
19struct array
20{
21    // types:
22    typedef T & reference;
23    typedef const T & const_reference;
24    typedef implementation defined iterator;
25    typedef implementation defined const_iterator;
26    typedef size_t size_type;
27    typedef ptrdiff_t difference_type;
28    typedef T value_type;
29    typedef T* pointer;
30    typedef const T* const_pointer;
31    typedef std::reverse_iterator<iterator> reverse_iterator;
32    typedef std::reverse_iterator<const_iterator> const_reverse_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
74template <class T, class... U>
75  array(T, U...) -> array<T, 1 + sizeof...(U)>;                 // C++17
76
77template <class T, size_t N>
78  bool operator==(const array<T,N>& x, const array<T,N>& y);    // constexpr in C++20
79template <class T, size_t N>
80  bool operator!=(const array<T,N>& x, const array<T,N>& y);    // constexpr in C++20
81template <class T, size_t N>
82  bool operator<(const array<T,N>& x, const array<T,N>& y);     // constexpr in C++20
83template <class T, size_t N>
84  bool operator>(const array<T,N>& x, const array<T,N>& y);     // constexpr in C++20
85template <class T, size_t N>
86  bool operator<=(const array<T,N>& x, const array<T,N>& y);    // constexpr in C++20
87template <class T, size_t N>
88  bool operator>=(const array<T,N>& x, const array<T,N>& y);    // constexpr in C++20
89
90template <class T, size_t N >
91  void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y))); // constexpr in C++20
92
93template <class T, size_t N>
94  constexpr array<remove_cv_t<T>, N> to_array(T (&a)[N]);  // C++20
95template <class T, size_t N>
96  constexpr array<remove_cv_t<T>, N> to_array(T (&&a)[N]); // C++20
97
98template <class T> struct tuple_size;
99template <size_t I, class T> struct tuple_element;
100template <class T, size_t N> struct tuple_size<array<T, N>>;
101template <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>;
102template <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept;               // constexpr in C++14
103template <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept;   // constexpr in C++14
104template <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept;             // constexpr in C++14
105template <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14
106
107}  // std
108
109*/
110
111#include <__algorithm/equal.h>
112#include <__algorithm/fill_n.h>
113#include <__algorithm/lexicographical_compare.h>
114#include <__algorithm/swap_ranges.h>
115#include <__assert> // all public C++ headers provide the assertion handler
116#include <__config>
117#include <__iterator/reverse_iterator.h>
118#include <__tuple/sfinae_helpers.h>
119#include <__type_traits/conditional.h>
120#include <__type_traits/is_array.h>
121#include <__type_traits/is_const.h>
122#include <__type_traits/is_constructible.h>
123#include <__type_traits/is_move_constructible.h>
124#include <__type_traits/is_nothrow_constructible.h>
125#include <__type_traits/is_nothrow_move_constructible.h>
126#include <__type_traits/is_same.h>
127#include <__type_traits/is_swappable.h>
128#include <__type_traits/remove_cv.h>
129#include <__utility/integer_sequence.h>
130#include <__utility/move.h>
131#include <__utility/unreachable.h>
132#include <stdexcept>
133#include <version>
134
135// standard-mandated includes
136
137// [iterator.range]
138#include <__iterator/access.h>
139#include <__iterator/data.h>
140#include <__iterator/empty.h>
141#include <__iterator/reverse_access.h>
142#include <__iterator/size.h>
143
144// [array.syn]
145#include <compare>
146#include <initializer_list>
147
148// [tuple.helper]
149#include <__tuple/tuple_element.h>
150#include <__tuple/tuple_size.h>
151
152#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
153#  pragma GCC system_header
154#endif
155
156_LIBCPP_BEGIN_NAMESPACE_STD
157
158template <class _Tp, size_t _Size>
159struct _LIBCPP_TEMPLATE_VIS array
160{
161    // types:
162    typedef array __self;
163    typedef _Tp                                   value_type;
164    typedef value_type&                           reference;
165    typedef const value_type&                     const_reference;
166    typedef value_type*                           iterator;
167    typedef const value_type*                     const_iterator;
168    typedef value_type*                           pointer;
169    typedef const value_type*                     const_pointer;
170    typedef size_t                                size_type;
171    typedef ptrdiff_t                             difference_type;
172    typedef _VSTD::reverse_iterator<iterator>       reverse_iterator;
173    typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
174
175    _Tp __elems_[_Size];
176
177    // No explicit construct/copy/destroy for aggregate type
178    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
179    void fill(const value_type& __u) {
180        _VSTD::fill_n(data(), _Size, __u);
181    }
182
183    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
184    void swap(array& __a) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) {
185        _VSTD::swap_ranges(data(), data() + _Size, __a.data());
186    }
187
188    // iterators:
189    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
190    iterator begin() _NOEXCEPT {return iterator(data());}
191    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
192    const_iterator begin() const _NOEXCEPT {return const_iterator(data());}
193    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
194    iterator end() _NOEXCEPT {return iterator(data() + _Size);}
195    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
196    const_iterator end() const _NOEXCEPT {return const_iterator(data() + _Size);}
197
198    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
199    reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
200    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
201    const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
202    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
203    reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
204    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
205    const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
206
207    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
208    const_iterator cbegin() const _NOEXCEPT {return begin();}
209    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
210    const_iterator cend() const _NOEXCEPT {return end();}
211    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
212    const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
213    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
214    const_reverse_iterator crend() const _NOEXCEPT {return rend();}
215
216    // capacity:
217    _LIBCPP_INLINE_VISIBILITY
218    _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;}
219    _LIBCPP_INLINE_VISIBILITY
220    _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;}
221    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
222    _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return _Size == 0;}
223
224    // element access:
225    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
226    reference operator[](size_type __n) _NOEXCEPT {
227        _LIBCPP_ASSERT(__n < _Size, "out-of-bounds access in std::array<T, N>");
228        return __elems_[__n];
229    }
230    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
231    const_reference operator[](size_type __n) const _NOEXCEPT {
232        _LIBCPP_ASSERT(__n < _Size, "out-of-bounds access in std::array<T, N>");
233        return __elems_[__n];
234    }
235
236    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference at(size_type __n)
237    {
238        if (__n >= _Size)
239            __throw_out_of_range("array::at");
240        return __elems_[__n];
241    }
242
243    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference at(size_type __n) const
244    {
245        if (__n >= _Size)
246            __throw_out_of_range("array::at");
247        return __elems_[__n];
248    }
249
250    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 reference front()             _NOEXCEPT {return (*this)[0];}
251    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference front() const _NOEXCEPT {return (*this)[0];}
252    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 reference back()              _NOEXCEPT {return (*this)[_Size - 1];}
253    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference back() const  _NOEXCEPT {return (*this)[_Size - 1];}
254
255    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
256    value_type* data() _NOEXCEPT {return __elems_;}
257    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
258    const value_type* data() const _NOEXCEPT {return __elems_;}
259};
260
261template <class _Tp>
262struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0>
263{
264    // types:
265    typedef array __self;
266    typedef _Tp                                   value_type;
267    typedef value_type&                           reference;
268    typedef const value_type&                     const_reference;
269    typedef value_type*                           iterator;
270    typedef const value_type*                     const_iterator;
271    typedef value_type*                           pointer;
272    typedef const value_type*                     const_pointer;
273    typedef size_t                                size_type;
274    typedef ptrdiff_t                             difference_type;
275    typedef _VSTD::reverse_iterator<iterator>       reverse_iterator;
276    typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
277
278    typedef __conditional_t<is_const<_Tp>::value, const char, char> _CharType;
279
280    struct  _ArrayInStructT { _Tp __data_[1]; };
281    _ALIGNAS_TYPE(_ArrayInStructT) _CharType __elems_[sizeof(_ArrayInStructT)];
282
283    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
284    value_type* data() _NOEXCEPT {return nullptr;}
285    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
286    const value_type* data() const _NOEXCEPT {return nullptr;}
287
288    // No explicit construct/copy/destroy for aggregate type
289    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
290    void fill(const value_type&) {
291      static_assert(!is_const<_Tp>::value,
292                    "cannot fill zero-sized array of type 'const T'");
293    }
294
295    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
296    void swap(array&) _NOEXCEPT {
297      static_assert(!is_const<_Tp>::value,
298                    "cannot swap zero-sized array of type 'const T'");
299    }
300
301    // iterators:
302    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
303    iterator begin() _NOEXCEPT {return iterator(data());}
304    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
305    const_iterator begin() const _NOEXCEPT {return const_iterator(data());}
306    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
307    iterator end() _NOEXCEPT {return iterator(data());}
308    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
309    const_iterator end() const _NOEXCEPT {return const_iterator(data());}
310
311    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
312    reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
313    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
314    const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
315    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
316    reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
317    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
318    const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
319
320    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
321    const_iterator cbegin() const _NOEXCEPT {return begin();}
322    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
323    const_iterator cend() const _NOEXCEPT {return end();}
324    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
325    const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
326    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
327    const_reverse_iterator crend() const _NOEXCEPT {return rend();}
328
329    // capacity:
330    _LIBCPP_INLINE_VISIBILITY
331    _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return 0; }
332    _LIBCPP_INLINE_VISIBILITY
333    _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return 0;}
334    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
335    _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return true;}
336
337    // element access:
338    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
339    reference operator[](size_type) _NOEXCEPT {
340      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
341      __libcpp_unreachable();
342    }
343
344    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
345    const_reference operator[](size_type) const _NOEXCEPT {
346      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
347      __libcpp_unreachable();
348    }
349
350    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
351    reference at(size_type) {
352      __throw_out_of_range("array<T, 0>::at");
353      __libcpp_unreachable();
354    }
355
356    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
357    const_reference at(size_type) const {
358      __throw_out_of_range("array<T, 0>::at");
359      __libcpp_unreachable();
360    }
361
362    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
363    reference front() _NOEXCEPT {
364      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
365      __libcpp_unreachable();
366    }
367
368    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
369    const_reference front() const _NOEXCEPT {
370      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
371      __libcpp_unreachable();
372    }
373
374    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
375    reference back() _NOEXCEPT {
376      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
377      __libcpp_unreachable();
378    }
379
380    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
381    const_reference back() const _NOEXCEPT {
382      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
383      __libcpp_unreachable();
384    }
385};
386
387
388#if _LIBCPP_STD_VER >= 17
389template<class _Tp, class... _Args,
390         class = enable_if_t<__all<_IsSame<_Tp, _Args>::value...>::value>
391         >
392array(_Tp, _Args...)
393  -> array<_Tp, 1 + sizeof...(_Args)>;
394#endif
395
396template <class _Tp, size_t _Size>
397inline _LIBCPP_INLINE_VISIBILITY
398_LIBCPP_CONSTEXPR_SINCE_CXX20 bool
399operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
400{
401    return _VSTD::equal(__x.begin(), __x.end(), __y.begin());
402}
403
404template <class _Tp, size_t _Size>
405inline _LIBCPP_INLINE_VISIBILITY
406_LIBCPP_CONSTEXPR_SINCE_CXX20 bool
407operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
408{
409    return !(__x == __y);
410}
411
412template <class _Tp, size_t _Size>
413inline _LIBCPP_INLINE_VISIBILITY
414_LIBCPP_CONSTEXPR_SINCE_CXX20 bool
415operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
416{
417    return _VSTD::lexicographical_compare(__x.begin(), __x.end(),
418                                          __y.begin(), __y.end());
419}
420
421template <class _Tp, size_t _Size>
422inline _LIBCPP_INLINE_VISIBILITY
423_LIBCPP_CONSTEXPR_SINCE_CXX20 bool
424operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
425{
426    return __y < __x;
427}
428
429template <class _Tp, size_t _Size>
430inline _LIBCPP_INLINE_VISIBILITY
431_LIBCPP_CONSTEXPR_SINCE_CXX20 bool
432operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
433{
434    return !(__y < __x);
435}
436
437template <class _Tp, size_t _Size>
438inline _LIBCPP_INLINE_VISIBILITY
439_LIBCPP_CONSTEXPR_SINCE_CXX20 bool
440operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
441{
442    return !(__x < __y);
443}
444
445template <class _Tp, size_t _Size>
446inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
447__enable_if_t<_Size == 0 || __is_swappable<_Tp>::value, void>
448swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y)
449                                  _NOEXCEPT_(noexcept(__x.swap(__y)))
450{
451    __x.swap(__y);
452}
453
454template <class _Tp, size_t _Size>
455struct _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> >
456    : public integral_constant<size_t, _Size> {};
457
458template <size_t _Ip, class _Tp, size_t _Size>
459struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> >
460{
461    static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)");
462    typedef _Tp type;
463};
464
465template <size_t _Ip, class _Tp, size_t _Size>
466inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
467_Tp&
468get(array<_Tp, _Size>& __a) _NOEXCEPT
469{
470    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)");
471    return __a.__elems_[_Ip];
472}
473
474template <size_t _Ip, class _Tp, size_t _Size>
475inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
476const _Tp&
477get(const array<_Tp, _Size>& __a) _NOEXCEPT
478{
479    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)");
480    return __a.__elems_[_Ip];
481}
482
483template <size_t _Ip, class _Tp, size_t _Size>
484inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
485_Tp&&
486get(array<_Tp, _Size>&& __a) _NOEXCEPT
487{
488    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)");
489    return _VSTD::move(__a.__elems_[_Ip]);
490}
491
492template <size_t _Ip, class _Tp, size_t _Size>
493inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
494const _Tp&&
495get(const array<_Tp, _Size>&& __a) _NOEXCEPT
496{
497    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)");
498    return _VSTD::move(__a.__elems_[_Ip]);
499}
500
501#if _LIBCPP_STD_VER >= 20
502
503template <typename _Tp, size_t _Size, size_t... _Index>
504_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size>
505__to_array_lvalue_impl(_Tp (&__arr)[_Size], index_sequence<_Index...>) {
506  return {{__arr[_Index]...}};
507}
508
509template <typename _Tp, size_t _Size, size_t... _Index>
510_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size>
511__to_array_rvalue_impl(_Tp(&&__arr)[_Size], index_sequence<_Index...>) {
512  return {{_VSTD::move(__arr[_Index])...}};
513}
514
515template <typename _Tp, size_t _Size>
516_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size>
517to_array(_Tp (&__arr)[_Size]) noexcept(is_nothrow_constructible_v<_Tp, _Tp&>) {
518  static_assert(
519      !is_array_v<_Tp>,
520      "[array.creation]/1: to_array does not accept multidimensional arrays.");
521  static_assert(
522      is_constructible_v<_Tp, _Tp&>,
523      "[array.creation]/1: to_array requires copy constructible elements.");
524  return _VSTD::__to_array_lvalue_impl(__arr, make_index_sequence<_Size>());
525}
526
527template <typename _Tp, size_t _Size>
528_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size>
529to_array(_Tp(&&__arr)[_Size]) noexcept(is_nothrow_move_constructible_v<_Tp>) {
530  static_assert(
531      !is_array_v<_Tp>,
532      "[array.creation]/4: to_array does not accept multidimensional arrays.");
533  static_assert(
534      is_move_constructible_v<_Tp>,
535      "[array.creation]/4: to_array requires move constructible elements.");
536  return _VSTD::__to_array_rvalue_impl(_VSTD::move(__arr),
537                                       make_index_sequence<_Size>());
538}
539
540#endif // _LIBCPP_STD_VER >= 20
541
542_LIBCPP_END_NAMESPACE_STD
543
544#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
545#  include <algorithm>
546#  include <concepts>
547#  include <cstdlib>
548#  include <iterator>
549#  include <type_traits>
550#  include <utility>
551#endif
552
553#endif // _LIBCPP_ARRAY
554