xref: /llvm-project-15.0.7/libcxx/include/array (revision 77b9abfc)
1// -*- C++ -*-
2//===---------------------------- array -----------------------------------===//
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 <__config>
112#include <__tuple>
113#include <type_traits>
114#include <utility>
115#include <iterator>
116#include <algorithm>
117#include <stdexcept>
118#include <cstdlib> // for _LIBCPP_UNREACHABLE
119#include <version>
120#include <__debug>
121
122#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
123#pragma GCC system_header
124#endif
125
126
127
128_LIBCPP_BEGIN_NAMESPACE_STD
129
130
131template <class _Tp, size_t _Size>
132struct _LIBCPP_TEMPLATE_VIS array
133{
134    // types:
135    typedef array __self;
136    typedef _Tp                                   value_type;
137    typedef value_type&                           reference;
138    typedef const value_type&                     const_reference;
139    typedef value_type*                           iterator;
140    typedef const value_type*                     const_iterator;
141    typedef value_type*                           pointer;
142    typedef const value_type*                     const_pointer;
143    typedef size_t                                size_type;
144    typedef ptrdiff_t                             difference_type;
145    typedef std::reverse_iterator<iterator>       reverse_iterator;
146    typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
147
148    _Tp __elems_[_Size];
149
150    // No explicit construct/copy/destroy for aggregate type
151    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
152    void fill(const value_type& __u) {
153      _VSTD::fill_n(__elems_, _Size, __u);
154    }
155
156    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
157    void swap(array& __a) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) {
158      std::swap_ranges(__elems_, __elems_ + _Size, __a.__elems_);
159    }
160
161    // iterators:
162    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
163    iterator begin() _NOEXCEPT {return iterator(data());}
164    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
165    const_iterator begin() const _NOEXCEPT {return const_iterator(data());}
166    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
167    iterator end() _NOEXCEPT {return iterator(data() + _Size);}
168    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
169    const_iterator end() const _NOEXCEPT {return const_iterator(data() + _Size);}
170
171    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
172    reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
173    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
174    const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
175    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
176    reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
177    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
178    const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
179
180    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
181    const_iterator cbegin() const _NOEXCEPT {return begin();}
182    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
183    const_iterator cend() const _NOEXCEPT {return end();}
184    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
185    const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
186    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
187    const_reverse_iterator crend() const _NOEXCEPT {return rend();}
188
189    // capacity:
190    _LIBCPP_INLINE_VISIBILITY
191    _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;}
192    _LIBCPP_INLINE_VISIBILITY
193    _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;}
194    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
195    _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return false; }
196
197    // element access:
198    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
199    reference operator[](size_type __n)             _NOEXCEPT {return __elems_[__n];}
200    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
201    const_reference operator[](size_type __n) const _NOEXCEPT {return __elems_[__n];}
202
203    _LIBCPP_CONSTEXPR_AFTER_CXX14 reference at(size_type __n)
204    {
205        if (__n >= _Size)
206            __throw_out_of_range("array::at");
207        return __elems_[__n];
208    }
209
210    _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const
211    {
212        if (__n >= _Size)
213            __throw_out_of_range("array::at");
214        return __elems_[__n];
215    }
216
217    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front()             _NOEXCEPT {return __elems_[0];}
218    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const _NOEXCEPT {return __elems_[0];}
219    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back()              _NOEXCEPT {return __elems_[_Size - 1];}
220    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const  _NOEXCEPT {return __elems_[_Size - 1];}
221
222    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
223    value_type* data() _NOEXCEPT {return __elems_;}
224    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
225    const value_type* data() const _NOEXCEPT {return __elems_;}
226};
227
228template <class _Tp>
229struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0>
230{
231    // types:
232    typedef array __self;
233    typedef _Tp                                   value_type;
234    typedef value_type&                           reference;
235    typedef const value_type&                     const_reference;
236    typedef value_type*                           iterator;
237    typedef const value_type*                     const_iterator;
238    typedef value_type*                           pointer;
239    typedef const value_type*                     const_pointer;
240    typedef size_t                                size_type;
241    typedef ptrdiff_t                             difference_type;
242    typedef std::reverse_iterator<iterator>       reverse_iterator;
243    typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
244
245#ifndef _LIBCPP_CXX03_LANG
246    union __wrapper {
247        _LIBCPP_CONSTEXPR __wrapper() : __b() { }
248        ~__wrapper() = default;
249
250        bool __b;
251        _Tp __t;
252    } __w;
253
254    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
255    value_type* data() _NOEXCEPT {return &__w.__t;}
256    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
257    const value_type* data() const _NOEXCEPT {return &__w.__t;}
258#else // C++03
259    typedef typename conditional<is_const<_Tp>::value, const char,
260                                char>::type _CharType;
261
262    struct  _ArrayInStructT { _Tp __data_[1]; };
263    _ALIGNAS_TYPE(_ArrayInStructT) _CharType __elems_[sizeof(_ArrayInStructT)];
264
265    _LIBCPP_INLINE_VISIBILITY
266    value_type* data() _NOEXCEPT {return reinterpret_cast<value_type*>(__elems_);}
267    _LIBCPP_INLINE_VISIBILITY
268    const value_type* data() const _NOEXCEPT {return reinterpret_cast<const value_type*>(__elems_);}
269#endif
270
271    // No explicit construct/copy/destroy for aggregate type
272    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
273    void fill(const value_type&) {
274      static_assert(!is_const<_Tp>::value,
275                    "cannot fill zero-sized array of type 'const T'");
276    }
277
278    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
279    void swap(array&) _NOEXCEPT {
280      static_assert(!is_const<_Tp>::value,
281                    "cannot swap zero-sized array of type 'const T'");
282    }
283
284    // iterators:
285    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
286    iterator begin() _NOEXCEPT {return iterator(data());}
287    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
288    const_iterator begin() const _NOEXCEPT {return const_iterator(data());}
289    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
290    iterator end() _NOEXCEPT {return iterator(data());}
291    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
292    const_iterator end() const _NOEXCEPT {return const_iterator(data());}
293
294    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
295    reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
296    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
297    const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
298    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
299    reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
300    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
301    const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
302
303    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
304    const_iterator cbegin() const _NOEXCEPT {return begin();}
305    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
306    const_iterator cend() const _NOEXCEPT {return end();}
307    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
308    const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
309    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
310    const_reverse_iterator crend() const _NOEXCEPT {return rend();}
311
312    // capacity:
313    _LIBCPP_INLINE_VISIBILITY
314    _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return 0; }
315    _LIBCPP_INLINE_VISIBILITY
316    _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return 0;}
317    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
318    _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return true;}
319
320    // element access:
321    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
322    reference operator[](size_type) _NOEXCEPT {
323      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
324      _LIBCPP_UNREACHABLE();
325    }
326
327    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
328    const_reference operator[](size_type) const _NOEXCEPT {
329      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
330      _LIBCPP_UNREACHABLE();
331    }
332
333    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
334    reference at(size_type) {
335      __throw_out_of_range("array<T, 0>::at");
336      _LIBCPP_UNREACHABLE();
337    }
338
339    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
340    const_reference at(size_type) const {
341      __throw_out_of_range("array<T, 0>::at");
342      _LIBCPP_UNREACHABLE();
343    }
344
345    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
346    reference front() _NOEXCEPT {
347      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
348      _LIBCPP_UNREACHABLE();
349    }
350
351    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
352    const_reference front() const _NOEXCEPT {
353      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
354      _LIBCPP_UNREACHABLE();
355    }
356
357    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
358    reference back() _NOEXCEPT {
359      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
360      _LIBCPP_UNREACHABLE();
361    }
362
363    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
364    const_reference back() const _NOEXCEPT {
365      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
366      _LIBCPP_UNREACHABLE();
367    }
368};
369
370
371#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
372template<class _Tp, class... _Args,
373         class = _EnableIf<__all<_IsSame<_Tp, _Args>::value...>::value>
374         >
375array(_Tp, _Args...)
376  -> array<_Tp, 1 + sizeof...(_Args)>;
377#endif
378
379template <class _Tp, size_t _Size>
380inline _LIBCPP_INLINE_VISIBILITY
381_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
382operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
383{
384    return _VSTD::equal(__x.begin(), __x.end(), __y.begin());
385}
386
387template <class _Tp, size_t _Size>
388inline _LIBCPP_INLINE_VISIBILITY
389_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
390operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
391{
392    return !(__x == __y);
393}
394
395template <class _Tp, size_t _Size>
396inline _LIBCPP_INLINE_VISIBILITY
397_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
398operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
399{
400    return _VSTD::lexicographical_compare(__x.begin(), __x.end(),
401                                          __y.begin(), __y.end());
402}
403
404template <class _Tp, size_t _Size>
405inline _LIBCPP_INLINE_VISIBILITY
406_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
407operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
408{
409    return __y < __x;
410}
411
412template <class _Tp, size_t _Size>
413inline _LIBCPP_INLINE_VISIBILITY
414_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
415operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
416{
417    return !(__y < __x);
418}
419
420template <class _Tp, size_t _Size>
421inline _LIBCPP_INLINE_VISIBILITY
422_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
423operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
424{
425    return !(__x < __y);
426}
427
428template <class _Tp, size_t _Size>
429inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
430typename enable_if
431<
432    _Size == 0 ||
433    __is_swappable<_Tp>::value,
434    void
435>::type
436swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y)
437                                  _NOEXCEPT_(noexcept(__x.swap(__y)))
438{
439    __x.swap(__y);
440}
441
442template <class _Tp, size_t _Size>
443struct _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> >
444    : public integral_constant<size_t, _Size> {};
445
446template <size_t _Ip, class _Tp, size_t _Size>
447struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> >
448{
449    static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)");
450    typedef _Tp type;
451};
452
453template <size_t _Ip, class _Tp, size_t _Size>
454inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
455_Tp&
456get(array<_Tp, _Size>& __a) _NOEXCEPT
457{
458    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)");
459    return __a.__elems_[_Ip];
460}
461
462template <size_t _Ip, class _Tp, size_t _Size>
463inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
464const _Tp&
465get(const array<_Tp, _Size>& __a) _NOEXCEPT
466{
467    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)");
468    return __a.__elems_[_Ip];
469}
470
471#ifndef _LIBCPP_CXX03_LANG
472
473template <size_t _Ip, class _Tp, size_t _Size>
474inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
475_Tp&&
476get(array<_Tp, _Size>&& __a) _NOEXCEPT
477{
478    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)");
479    return _VSTD::move(__a.__elems_[_Ip]);
480}
481
482template <size_t _Ip, class _Tp, size_t _Size>
483inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
484const _Tp&&
485get(const array<_Tp, _Size>&& __a) _NOEXCEPT
486{
487    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)");
488    return _VSTD::move(__a.__elems_[_Ip]);
489}
490
491#endif  // !_LIBCPP_CXX03_LANG
492
493#if _LIBCPP_STD_VER > 17
494
495template <typename _Tp, size_t _Size, size_t... _Index>
496_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size>
497__to_array_lvalue_impl(_Tp (&__arr)[_Size], index_sequence<_Index...>) {
498  return {{__arr[_Index]...}};
499}
500
501template <typename _Tp, size_t _Size, size_t... _Index>
502_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size>
503__to_array_rvalue_impl(_Tp(&&__arr)[_Size], index_sequence<_Index...>) {
504  return {{_VSTD::move(__arr[_Index])...}};
505}
506
507template <typename _Tp, size_t _Size>
508_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size>
509to_array(_Tp (&__arr)[_Size]) noexcept(is_nothrow_constructible_v<_Tp, _Tp&>) {
510  static_assert(
511      !is_array_v<_Tp>,
512      "[array.creation]/1: to_array does not accept multidimensional arrays.");
513  static_assert(
514      is_constructible_v<_Tp, _Tp&>,
515      "[array.creation]/1: to_array requires copy constructible elements.");
516  return __to_array_lvalue_impl(__arr, make_index_sequence<_Size>());
517}
518
519template <typename _Tp, size_t _Size>
520_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size>
521to_array(_Tp(&&__arr)[_Size]) noexcept(is_nothrow_move_constructible_v<_Tp>) {
522  static_assert(
523      !is_array_v<_Tp>,
524      "[array.creation]/4: to_array does not accept multidimensional arrays.");
525  static_assert(
526      is_move_constructible_v<_Tp>,
527      "[array.creation]/4: to_array requires move constructible elements.");
528  return __to_array_rvalue_impl(_VSTD::move(__arr),
529                                make_index_sequence<_Size>());
530}
531
532#endif // _LIBCPP_STD_VER > 17
533
534_LIBCPP_END_NAMESPACE_STD
535
536#endif  // _LIBCPP_ARRAY
537