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