xref: /llvm-project-15.0.7/libcxx/include/array (revision 0800529f)
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    typedef typename conditional<is_const<_Tp>::value, const char,
246                                char>::type _CharType;
247
248    struct  _ArrayInStructT { _Tp __data_[1]; };
249    _ALIGNAS_TYPE(_ArrayInStructT) _CharType __elems_[sizeof(_ArrayInStructT)];
250
251    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
252    value_type* data() _NOEXCEPT {return nullptr;}
253    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
254    const value_type* data() const _NOEXCEPT {return nullptr;}
255
256    // No explicit construct/copy/destroy for aggregate type
257    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
258    void fill(const value_type&) {
259      static_assert(!is_const<_Tp>::value,
260                    "cannot fill zero-sized array of type 'const T'");
261    }
262
263    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
264    void swap(array&) _NOEXCEPT {
265      static_assert(!is_const<_Tp>::value,
266                    "cannot swap zero-sized array of type 'const T'");
267    }
268
269    // iterators:
270    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
271    iterator begin() _NOEXCEPT {return iterator(data());}
272    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
273    const_iterator begin() const _NOEXCEPT {return const_iterator(data());}
274    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
275    iterator end() _NOEXCEPT {return iterator(data());}
276    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
277    const_iterator end() const _NOEXCEPT {return const_iterator(data());}
278
279    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
280    reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
281    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
282    const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
283    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
284    reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
285    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
286    const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
287
288    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
289    const_iterator cbegin() const _NOEXCEPT {return begin();}
290    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
291    const_iterator cend() const _NOEXCEPT {return end();}
292    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
293    const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
294    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
295    const_reverse_iterator crend() const _NOEXCEPT {return rend();}
296
297    // capacity:
298    _LIBCPP_INLINE_VISIBILITY
299    _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return 0; }
300    _LIBCPP_INLINE_VISIBILITY
301    _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return 0;}
302    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
303    _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return true;}
304
305    // element access:
306    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
307    reference operator[](size_type) _NOEXCEPT {
308      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
309      _LIBCPP_UNREACHABLE();
310    }
311
312    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
313    const_reference operator[](size_type) const _NOEXCEPT {
314      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
315      _LIBCPP_UNREACHABLE();
316    }
317
318    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
319    reference at(size_type) {
320      __throw_out_of_range("array<T, 0>::at");
321      _LIBCPP_UNREACHABLE();
322    }
323
324    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
325    const_reference at(size_type) const {
326      __throw_out_of_range("array<T, 0>::at");
327      _LIBCPP_UNREACHABLE();
328    }
329
330    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
331    reference front() _NOEXCEPT {
332      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
333      _LIBCPP_UNREACHABLE();
334    }
335
336    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
337    const_reference front() const _NOEXCEPT {
338      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
339      _LIBCPP_UNREACHABLE();
340    }
341
342    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
343    reference back() _NOEXCEPT {
344      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
345      _LIBCPP_UNREACHABLE();
346    }
347
348    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
349    const_reference back() const _NOEXCEPT {
350      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
351      _LIBCPP_UNREACHABLE();
352    }
353};
354
355
356#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
357template<class _Tp, class... _Args,
358         class = _EnableIf<__all<_IsSame<_Tp, _Args>::value...>::value>
359         >
360array(_Tp, _Args...)
361  -> array<_Tp, 1 + sizeof...(_Args)>;
362#endif
363
364template <class _Tp, size_t _Size>
365inline _LIBCPP_INLINE_VISIBILITY
366_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
367operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
368{
369    return _VSTD::equal(__x.begin(), __x.end(), __y.begin());
370}
371
372template <class _Tp, size_t _Size>
373inline _LIBCPP_INLINE_VISIBILITY
374_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
375operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
376{
377    return !(__x == __y);
378}
379
380template <class _Tp, size_t _Size>
381inline _LIBCPP_INLINE_VISIBILITY
382_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
383operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
384{
385    return _VSTD::lexicographical_compare(__x.begin(), __x.end(),
386                                          __y.begin(), __y.end());
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 __y < __x;
395}
396
397template <class _Tp, size_t _Size>
398inline _LIBCPP_INLINE_VISIBILITY
399_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
400operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
401{
402    return !(__y < __x);
403}
404
405template <class _Tp, size_t _Size>
406inline _LIBCPP_INLINE_VISIBILITY
407_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
408operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
409{
410    return !(__x < __y);
411}
412
413template <class _Tp, size_t _Size>
414inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
415typename enable_if
416<
417    _Size == 0 ||
418    __is_swappable<_Tp>::value,
419    void
420>::type
421swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y)
422                                  _NOEXCEPT_(noexcept(__x.swap(__y)))
423{
424    __x.swap(__y);
425}
426
427template <class _Tp, size_t _Size>
428struct _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> >
429    : public integral_constant<size_t, _Size> {};
430
431template <size_t _Ip, class _Tp, size_t _Size>
432struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> >
433{
434    static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)");
435    typedef _Tp type;
436};
437
438template <size_t _Ip, class _Tp, size_t _Size>
439inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
440_Tp&
441get(array<_Tp, _Size>& __a) _NOEXCEPT
442{
443    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)");
444    return __a.__elems_[_Ip];
445}
446
447template <size_t _Ip, class _Tp, size_t _Size>
448inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
449const _Tp&
450get(const array<_Tp, _Size>& __a) _NOEXCEPT
451{
452    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)");
453    return __a.__elems_[_Ip];
454}
455
456#ifndef _LIBCPP_CXX03_LANG
457
458template <size_t _Ip, class _Tp, size_t _Size>
459inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
460_Tp&&
461get(array<_Tp, _Size>&& __a) _NOEXCEPT
462{
463    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)");
464    return _VSTD::move(__a.__elems_[_Ip]);
465}
466
467template <size_t _Ip, class _Tp, size_t _Size>
468inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
469const _Tp&&
470get(const array<_Tp, _Size>&& __a) _NOEXCEPT
471{
472    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)");
473    return _VSTD::move(__a.__elems_[_Ip]);
474}
475
476#endif  // !_LIBCPP_CXX03_LANG
477
478#if _LIBCPP_STD_VER > 17
479
480template <typename _Tp, size_t _Size, size_t... _Index>
481_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size>
482__to_array_lvalue_impl(_Tp (&__arr)[_Size], index_sequence<_Index...>) {
483  return {{__arr[_Index]...}};
484}
485
486template <typename _Tp, size_t _Size, size_t... _Index>
487_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size>
488__to_array_rvalue_impl(_Tp(&&__arr)[_Size], index_sequence<_Index...>) {
489  return {{_VSTD::move(__arr[_Index])...}};
490}
491
492template <typename _Tp, size_t _Size>
493_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size>
494to_array(_Tp (&__arr)[_Size]) noexcept(is_nothrow_constructible_v<_Tp, _Tp&>) {
495  static_assert(
496      !is_array_v<_Tp>,
497      "[array.creation]/1: to_array does not accept multidimensional arrays.");
498  static_assert(
499      is_constructible_v<_Tp, _Tp&>,
500      "[array.creation]/1: to_array requires copy constructible elements.");
501  return __to_array_lvalue_impl(__arr, make_index_sequence<_Size>());
502}
503
504template <typename _Tp, size_t _Size>
505_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size>
506to_array(_Tp(&&__arr)[_Size]) noexcept(is_nothrow_move_constructible_v<_Tp>) {
507  static_assert(
508      !is_array_v<_Tp>,
509      "[array.creation]/4: to_array does not accept multidimensional arrays.");
510  static_assert(
511      is_move_constructible_v<_Tp>,
512      "[array.creation]/4: to_array requires move constructible elements.");
513  return __to_array_rvalue_impl(_VSTD::move(__arr),
514                                make_index_sequence<_Size>());
515}
516
517#endif // _LIBCPP_STD_VER > 17
518
519_LIBCPP_END_NAMESPACE_STD
520
521#endif  // _LIBCPP_ARRAY
522