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