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