xref: /llvm-project-15.0.7/libcxx/include/array (revision 0161874c)
13e519524SHoward Hinnant// -*- C++ -*-
23e519524SHoward Hinnant//===---------------------------- array -----------------------------------===//
33e519524SHoward Hinnant//
457b08b09SChandler Carruth// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
557b08b09SChandler Carruth// See https://llvm.org/LICENSE.txt for license information.
657b08b09SChandler Carruth// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
73e519524SHoward Hinnant//
83e519524SHoward Hinnant//===----------------------------------------------------------------------===//
93e519524SHoward Hinnant
103e519524SHoward Hinnant#ifndef _LIBCPP_ARRAY
113e519524SHoward Hinnant#define _LIBCPP_ARRAY
123e519524SHoward Hinnant
133e519524SHoward Hinnant/*
143e519524SHoward Hinnant    array synopsis
153e519524SHoward Hinnant
163e519524SHoward Hinnantnamespace std
173e519524SHoward Hinnant{
183e519524SHoward Hinnanttemplate <class T, size_t N >
193e519524SHoward Hinnantstruct array
203e519524SHoward Hinnant{
213e519524SHoward Hinnant    // types:
223e519524SHoward Hinnant    typedef T & reference;
233e519524SHoward Hinnant    typedef const T & const_reference;
243e519524SHoward Hinnant    typedef implementation defined iterator;
253e519524SHoward Hinnant    typedef implementation defined const_iterator;
263e519524SHoward Hinnant    typedef size_t size_type;
273e519524SHoward Hinnant    typedef ptrdiff_t difference_type;
283e519524SHoward Hinnant    typedef T value_type;
293e519524SHoward Hinnant    typedef T* pointer;
303e519524SHoward Hinnant    typedef const T* const_pointer;
313e519524SHoward Hinnant    typedef std::reverse_iterator<iterator> reverse_iterator;
323e519524SHoward Hinnant    typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
333e519524SHoward Hinnant
343e519524SHoward Hinnant    // No explicit construct/copy/destroy for aggregate type
353e519524SHoward Hinnant    void fill(const T& u);
36f07dd8d0SEric Fiselier    void swap(array& a) noexcept(is_nothrow_swappable_v<T>);
373e519524SHoward Hinnant
383e519524SHoward Hinnant    // iterators:
398f0cd597SHoward Hinnant    iterator begin() noexcept;
408f0cd597SHoward Hinnant    const_iterator begin() const noexcept;
418f0cd597SHoward Hinnant    iterator end() noexcept;
428f0cd597SHoward Hinnant    const_iterator end() const noexcept;
433e519524SHoward Hinnant
448f0cd597SHoward Hinnant    reverse_iterator rbegin() noexcept;
458f0cd597SHoward Hinnant    const_reverse_iterator rbegin() const noexcept;
468f0cd597SHoward Hinnant    reverse_iterator rend() noexcept;
478f0cd597SHoward Hinnant    const_reverse_iterator rend() const noexcept;
483e519524SHoward Hinnant
498f0cd597SHoward Hinnant    const_iterator cbegin() const noexcept;
508f0cd597SHoward Hinnant    const_iterator cend() const noexcept;
518f0cd597SHoward Hinnant    const_reverse_iterator crbegin() const noexcept;
528f0cd597SHoward Hinnant    const_reverse_iterator crend() const noexcept;
533e519524SHoward Hinnant
543e519524SHoward Hinnant    // capacity:
558f0cd597SHoward Hinnant    constexpr size_type size() const noexcept;
568f0cd597SHoward Hinnant    constexpr size_type max_size() const noexcept;
57397717b7SHoward Hinnant    constexpr bool empty() const noexcept;
583e519524SHoward Hinnant
593e519524SHoward Hinnant    // element access:
603e519524SHoward Hinnant    reference operator[](size_type n);
618bf1f08aSMarshall Clow    const_reference operator[](size_type n) const; // constexpr in C++14
628bf1f08aSMarshall Clow    const_reference at(size_type n) const; // constexpr in C++14
633e519524SHoward Hinnant    reference at(size_type n);
643e519524SHoward Hinnant
653e519524SHoward Hinnant    reference front();
668bf1f08aSMarshall Clow    const_reference front() const; // constexpr in C++14
673e519524SHoward Hinnant    reference back();
688bf1f08aSMarshall Clow    const_reference back() const; // constexpr in C++14
693e519524SHoward Hinnant
708f0cd597SHoward Hinnant    T* data() noexcept;
718f0cd597SHoward Hinnant    const T* data() const noexcept;
723e519524SHoward Hinnant};
733e519524SHoward Hinnant
740ca8c089SMarshall Clow  template <class T, class... U>
750ca8c089SMarshall Clow    array(T, U...) -> array<T, 1 + sizeof...(U)>;
760ca8c089SMarshall Clow
773e519524SHoward Hinnanttemplate <class T, size_t N>
783e519524SHoward Hinnant  bool operator==(const array<T,N>& x, const array<T,N>& y);
793e519524SHoward Hinnanttemplate <class T, size_t N>
803e519524SHoward Hinnant  bool operator!=(const array<T,N>& x, const array<T,N>& y);
813e519524SHoward Hinnanttemplate <class T, size_t N>
823e519524SHoward Hinnant  bool operator<(const array<T,N>& x, const array<T,N>& y);
833e519524SHoward Hinnanttemplate <class T, size_t N>
843e519524SHoward Hinnant  bool operator>(const array<T,N>& x, const array<T,N>& y);
853e519524SHoward Hinnanttemplate <class T, size_t N>
863e519524SHoward Hinnant  bool operator<=(const array<T,N>& x, const array<T,N>& y);
873e519524SHoward Hinnanttemplate <class T, size_t N>
883e519524SHoward Hinnant  bool operator>=(const array<T,N>& x, const array<T,N>& y);
893e519524SHoward Hinnant
903e519524SHoward Hinnanttemplate <class T, size_t N >
910ca8c089SMarshall Clow  void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y))); // C++17
923e519524SHoward Hinnant
93e4957601SMarshall Clowtemplate <class T> struct tuple_size;
942b0c7abbSLouis Dionnetemplate <size_t I, class T> struct tuple_element;
953e519524SHoward Hinnanttemplate <class T, size_t N> struct tuple_size<array<T, N>>;
965fcc8169SMarshall Clowtemplate <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>;
975fcc8169SMarshall Clowtemplate <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14
985fcc8169SMarshall Clowtemplate <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++14
995fcc8169SMarshall Clowtemplate <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14
100545b8861SEric Fiseliertemplate <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14
1013e519524SHoward Hinnant
1023e519524SHoward Hinnant}  // std
1033e519524SHoward Hinnant
1043e519524SHoward Hinnant*/
1053e519524SHoward Hinnant
1063e519524SHoward Hinnant#include <__config>
1073e519524SHoward Hinnant#include <__tuple>
1083e519524SHoward Hinnant#include <type_traits>
1093e519524SHoward Hinnant#include <utility>
1103e519524SHoward Hinnant#include <iterator>
1113e519524SHoward Hinnant#include <algorithm>
1123e519524SHoward Hinnant#include <stdexcept>
11359cdf90aSEric Fiselier#include <cstdlib> // for _LIBCPP_UNREACHABLE
114f56972e2SMarshall Clow#include <version>
11559cdf90aSEric Fiselier#include <__debug>
1163e519524SHoward Hinnant
117073458b1SHoward Hinnant#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1183e519524SHoward Hinnant#pragma GCC system_header
119073458b1SHoward Hinnant#endif
1203e519524SHoward Hinnant
121a016efb1SEric Fiselier
122a016efb1SEric Fiselier
1233e519524SHoward Hinnant_LIBCPP_BEGIN_NAMESPACE_STD
1243e519524SHoward Hinnant
12559cdf90aSEric Fiselier
1263e519524SHoward Hinnanttemplate <class _Tp, size_t _Size>
127e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS array
1283e519524SHoward Hinnant{
1293e519524SHoward Hinnant    // types:
1303e519524SHoward Hinnant    typedef array __self;
1313e519524SHoward Hinnant    typedef _Tp                                   value_type;
1323e519524SHoward Hinnant    typedef value_type&                           reference;
1333e519524SHoward Hinnant    typedef const value_type&                     const_reference;
1343e519524SHoward Hinnant    typedef value_type*                           iterator;
1353e519524SHoward Hinnant    typedef const value_type*                     const_iterator;
1363e519524SHoward Hinnant    typedef value_type*                           pointer;
1373e519524SHoward Hinnant    typedef const value_type*                     const_pointer;
1383e519524SHoward Hinnant    typedef size_t                                size_type;
1393e519524SHoward Hinnant    typedef ptrdiff_t                             difference_type;
1403e519524SHoward Hinnant    typedef std::reverse_iterator<iterator>       reverse_iterator;
1413e519524SHoward Hinnant    typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
1423e519524SHoward Hinnant
14359cdf90aSEric Fiselier    _Tp __elems_[_Size];
1443e519524SHoward Hinnant
1453e519524SHoward Hinnant    // No explicit construct/copy/destroy for aggregate type
14659cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY void fill(const value_type& __u) {
14759cdf90aSEric Fiselier      _VSTD::fill_n(__elems_, _Size, __u);
14859cdf90aSEric Fiselier    }
149afeda5c2SEric Fiselier
1508f0cd597SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
15159cdf90aSEric Fiselier    void swap(array& __a) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) {
15259cdf90aSEric Fiselier      std::swap_ranges(__elems_, __elems_ + _Size, __a.__elems_);
15359cdf90aSEric Fiselier    }
1543e519524SHoward Hinnant
1553e519524SHoward Hinnant    // iterators:
156020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
15759cdf90aSEric Fiselier    iterator begin() _NOEXCEPT {return iterator(data());}
158020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
15959cdf90aSEric Fiselier    const_iterator begin() const _NOEXCEPT {return const_iterator(data());}
160020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16159cdf90aSEric Fiselier    iterator end() _NOEXCEPT {return iterator(data() + _Size);}
162020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16359cdf90aSEric Fiselier    const_iterator end() const _NOEXCEPT {return const_iterator(data() + _Size);}
1643e519524SHoward Hinnant
165020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1668f0cd597SHoward Hinnant    reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
167020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1688f0cd597SHoward Hinnant    const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
169020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1708f0cd597SHoward Hinnant    reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
171020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1728f0cd597SHoward Hinnant    const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
1733e519524SHoward Hinnant
174020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1758f0cd597SHoward Hinnant    const_iterator cbegin() const _NOEXCEPT {return begin();}
176020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1778f0cd597SHoward Hinnant    const_iterator cend() const _NOEXCEPT {return end();}
178020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1798f0cd597SHoward Hinnant    const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
180020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1818f0cd597SHoward Hinnant    const_reverse_iterator crend() const _NOEXCEPT {return rend();}
1823e519524SHoward Hinnant
1833e519524SHoward Hinnant    // capacity:
1848f0cd597SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
185397717b7SHoward Hinnant    _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;}
1868f0cd597SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
187397717b7SHoward Hinnant    _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;}
18872c8fad4SMarshall Clow    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
18959cdf90aSEric Fiselier    _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return false; }
1903e519524SHoward Hinnant
1913e519524SHoward Hinnant    // element access:
192e7826950SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1935f6a5ac1SMarshall Clow    reference operator[](size_type __n)             _NOEXCEPT {return __elems_[__n];}
194e7826950SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1955f6a5ac1SMarshall Clow    const_reference operator[](size_type __n) const _NOEXCEPT {return __elems_[__n];}
196e7826950SMarshall Clow
197*0161874cSLouis Dionne    _LIBCPP_CONSTEXPR_AFTER_CXX14 reference at(size_type __n)
198*0161874cSLouis Dionne    {
199*0161874cSLouis Dionne        if (__n >= _Size)
200*0161874cSLouis Dionne            __throw_out_of_range("array::at");
201*0161874cSLouis Dionne        return __elems_[__n];
202*0161874cSLouis Dionne    }
203*0161874cSLouis Dionne
204*0161874cSLouis Dionne    _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const
205*0161874cSLouis Dionne    {
206*0161874cSLouis Dionne        if (__n >= _Size)
207*0161874cSLouis Dionne            __throw_out_of_range("array::at");
208*0161874cSLouis Dionne        return __elems_[__n];
209*0161874cSLouis Dionne    }
2103e519524SHoward Hinnant
2119ea0e473SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front()             _NOEXCEPT {return __elems_[0];}
2129ea0e473SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const _NOEXCEPT {return __elems_[0];}
2139ea0e473SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back()              _NOEXCEPT {return __elems_[_Size - 1];}
2149ea0e473SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const  _NOEXCEPT {return __elems_[_Size - 1];}
2153e519524SHoward Hinnant
216020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
217936ff584SNirav Dave    value_type* data() _NOEXCEPT {return __elems_;}
218020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
219936ff584SNirav Dave    const value_type* data() const _NOEXCEPT {return __elems_;}
2203e519524SHoward Hinnant};
2213e519524SHoward Hinnant
22259cdf90aSEric Fiseliertemplate <class _Tp>
22359cdf90aSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS array<_Tp, 0>
22459cdf90aSEric Fiselier{
22559cdf90aSEric Fiselier    // types:
22659cdf90aSEric Fiselier    typedef array __self;
22759cdf90aSEric Fiselier    typedef _Tp                                   value_type;
22859cdf90aSEric Fiselier    typedef value_type&                           reference;
22959cdf90aSEric Fiselier    typedef const value_type&                     const_reference;
23059cdf90aSEric Fiselier    typedef value_type*                           iterator;
23159cdf90aSEric Fiselier    typedef const value_type*                     const_iterator;
23259cdf90aSEric Fiselier    typedef value_type*                           pointer;
23359cdf90aSEric Fiselier    typedef const value_type*                     const_pointer;
23459cdf90aSEric Fiselier    typedef size_t                                size_type;
23559cdf90aSEric Fiselier    typedef ptrdiff_t                             difference_type;
23659cdf90aSEric Fiselier    typedef std::reverse_iterator<iterator>       reverse_iterator;
23759cdf90aSEric Fiselier    typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
23859cdf90aSEric Fiselier
23959cdf90aSEric Fiselier    typedef typename conditional<is_const<_Tp>::value, const char,
24059cdf90aSEric Fiselier                                char>::type _CharType;
2411a78ae3cSEric Fiselier
2421a78ae3cSEric Fiselier    struct  _ArrayInStructT { _Tp __data_[1]; };
2431a78ae3cSEric Fiselier    _ALIGNAS_TYPE(_ArrayInStructT) _CharType __elems_[sizeof(_ArrayInStructT)];
24459cdf90aSEric Fiselier
24559cdf90aSEric Fiselier    // No explicit construct/copy/destroy for aggregate type
24659cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY void fill(const value_type&) {
24759cdf90aSEric Fiselier      static_assert(!is_const<_Tp>::value,
24859cdf90aSEric Fiselier                    "cannot fill zero-sized array of type 'const T'");
24959cdf90aSEric Fiselier    }
25059cdf90aSEric Fiselier
25159cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
25259cdf90aSEric Fiselier    void swap(array&) _NOEXCEPT {
25359cdf90aSEric Fiselier      static_assert(!is_const<_Tp>::value,
25459cdf90aSEric Fiselier                    "cannot swap zero-sized array of type 'const T'");
25559cdf90aSEric Fiselier    }
25659cdf90aSEric Fiselier
25759cdf90aSEric Fiselier    // iterators:
25859cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
25959cdf90aSEric Fiselier    iterator begin() _NOEXCEPT {return iterator(data());}
26059cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
26159cdf90aSEric Fiselier    const_iterator begin() const _NOEXCEPT {return const_iterator(data());}
26259cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
26359cdf90aSEric Fiselier    iterator end() _NOEXCEPT {return iterator(data());}
26459cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
26559cdf90aSEric Fiselier    const_iterator end() const _NOEXCEPT {return const_iterator(data());}
26659cdf90aSEric Fiselier
26759cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
26859cdf90aSEric Fiselier    reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
26959cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
27059cdf90aSEric Fiselier    const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
27159cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
27259cdf90aSEric Fiselier    reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
27359cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
27459cdf90aSEric Fiselier    const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
27559cdf90aSEric Fiselier
27659cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
27759cdf90aSEric Fiselier    const_iterator cbegin() const _NOEXCEPT {return begin();}
27859cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
27959cdf90aSEric Fiselier    const_iterator cend() const _NOEXCEPT {return end();}
28059cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
28159cdf90aSEric Fiselier    const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
28259cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
28359cdf90aSEric Fiselier    const_reverse_iterator crend() const _NOEXCEPT {return rend();}
28459cdf90aSEric Fiselier
28559cdf90aSEric Fiselier    // capacity:
28659cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
28759cdf90aSEric Fiselier    _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return 0; }
28859cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
28959cdf90aSEric Fiselier    _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return 0;}
29059cdf90aSEric Fiselier    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
29159cdf90aSEric Fiselier    _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return true;}
29259cdf90aSEric Fiselier
29359cdf90aSEric Fiselier    // element access:
29459cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
2955f6a5ac1SMarshall Clow    reference operator[](size_type) _NOEXCEPT {
29659cdf90aSEric Fiselier      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
29759cdf90aSEric Fiselier      _LIBCPP_UNREACHABLE();
29859cdf90aSEric Fiselier    }
29959cdf90aSEric Fiselier
30059cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
3015f6a5ac1SMarshall Clow    const_reference operator[](size_type) const _NOEXCEPT {
30259cdf90aSEric Fiselier      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
30359cdf90aSEric Fiselier      _LIBCPP_UNREACHABLE();
30459cdf90aSEric Fiselier    }
30559cdf90aSEric Fiselier
30659cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
30759cdf90aSEric Fiselier    reference at(size_type) {
30859cdf90aSEric Fiselier      __throw_out_of_range("array<T, 0>::at");
30959cdf90aSEric Fiselier      _LIBCPP_UNREACHABLE();
31059cdf90aSEric Fiselier    }
31159cdf90aSEric Fiselier
31259cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
31359cdf90aSEric Fiselier    const_reference at(size_type) const {
31459cdf90aSEric Fiselier      __throw_out_of_range("array<T, 0>::at");
31559cdf90aSEric Fiselier      _LIBCPP_UNREACHABLE();
31659cdf90aSEric Fiselier    }
31759cdf90aSEric Fiselier
31859cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
3199ea0e473SMarshall Clow    reference front() _NOEXCEPT {
32059cdf90aSEric Fiselier      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
32159cdf90aSEric Fiselier      _LIBCPP_UNREACHABLE();
32259cdf90aSEric Fiselier    }
32359cdf90aSEric Fiselier
32459cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
3259ea0e473SMarshall Clow    const_reference front() const _NOEXCEPT {
32659cdf90aSEric Fiselier      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
32759cdf90aSEric Fiselier      _LIBCPP_UNREACHABLE();
32859cdf90aSEric Fiselier    }
32959cdf90aSEric Fiselier
33059cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
3319ea0e473SMarshall Clow    reference back() _NOEXCEPT {
33259cdf90aSEric Fiselier      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
33359cdf90aSEric Fiselier      _LIBCPP_UNREACHABLE();
33459cdf90aSEric Fiselier    }
33559cdf90aSEric Fiselier
33659cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
3379ea0e473SMarshall Clow    const_reference back() const _NOEXCEPT {
33859cdf90aSEric Fiselier      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
33959cdf90aSEric Fiselier      _LIBCPP_UNREACHABLE();
34059cdf90aSEric Fiselier    }
34159cdf90aSEric Fiselier
34259cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
34359cdf90aSEric Fiselier    value_type* data() _NOEXCEPT {return reinterpret_cast<value_type*>(__elems_);}
34459cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
34559cdf90aSEric Fiselier    const value_type* data() const _NOEXCEPT {return reinterpret_cast<const value_type*>(__elems_);}
34659cdf90aSEric Fiselier};
34759cdf90aSEric Fiselier
34859cdf90aSEric Fiselier
3490ca8c089SMarshall Clow#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
3500ca8c089SMarshall Clowtemplate<class _Tp, class... _Args,
351c6eb584cSEric Fiselier         class = _EnableIf<__all<_IsSame<_Tp, _Args>::value...>::value>
3520ca8c089SMarshall Clow         >
3530ca8c089SMarshall Clowarray(_Tp, _Args...)
3540ca8c089SMarshall Clow  -> array<_Tp, 1 + sizeof...(_Args)>;
3550ca8c089SMarshall Clow#endif
3560ca8c089SMarshall Clow
3573e519524SHoward Hinnanttemplate <class _Tp, size_t _Size>
3583af48ef7SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
35907d8ac0aSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
3603e519524SHoward Hinnantoperator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
3613e519524SHoward Hinnant{
36259cdf90aSEric Fiselier    return _VSTD::equal(__x.begin(), __x.end(), __y.begin());
3633e519524SHoward Hinnant}
3643e519524SHoward Hinnant
3653e519524SHoward Hinnanttemplate <class _Tp, size_t _Size>
3663af48ef7SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
36707d8ac0aSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
3683e519524SHoward Hinnantoperator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
3693e519524SHoward Hinnant{
3703e519524SHoward Hinnant    return !(__x == __y);
3713e519524SHoward Hinnant}
3723e519524SHoward Hinnant
3733e519524SHoward Hinnanttemplate <class _Tp, size_t _Size>
3743af48ef7SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
37507d8ac0aSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
3763e519524SHoward Hinnantoperator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
3773e519524SHoward Hinnant{
37859cdf90aSEric Fiselier    return _VSTD::lexicographical_compare(__x.begin(), __x.end(),
37959cdf90aSEric Fiselier                                          __y.begin(), __y.end());
3803e519524SHoward Hinnant}
3813e519524SHoward Hinnant
3823e519524SHoward Hinnanttemplate <class _Tp, size_t _Size>
3833af48ef7SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
38407d8ac0aSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
3853e519524SHoward Hinnantoperator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
3863e519524SHoward Hinnant{
3873e519524SHoward Hinnant    return __y < __x;
3883e519524SHoward Hinnant}
3893e519524SHoward Hinnant
3903e519524SHoward Hinnanttemplate <class _Tp, size_t _Size>
3913af48ef7SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
39207d8ac0aSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
3933e519524SHoward Hinnantoperator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
3943e519524SHoward Hinnant{
3953e519524SHoward Hinnant    return !(__y < __x);
3963e519524SHoward Hinnant}
3973e519524SHoward Hinnant
3983e519524SHoward Hinnanttemplate <class _Tp, size_t _Size>
3993af48ef7SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
40007d8ac0aSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
4013e519524SHoward Hinnantoperator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
4023e519524SHoward Hinnant{
4033e519524SHoward Hinnant    return !(__x < __y);
4043e519524SHoward Hinnant}
4053e519524SHoward Hinnant
4063e519524SHoward Hinnanttemplate <class _Tp, size_t _Size>
4073af48ef7SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
408bc95cf0dSHoward Hinnanttypename enable_if
409bc95cf0dSHoward Hinnant<
410f07dd8d0SEric Fiselier    _Size == 0 ||
411bc95cf0dSHoward Hinnant    __is_swappable<_Tp>::value,
4123e519524SHoward Hinnant    void
413bc95cf0dSHoward Hinnant>::type
414ee66eb13SMarshall Clowswap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y)
415f07dd8d0SEric Fiselier                                  _NOEXCEPT_(noexcept(__x.swap(__y)))
4163e519524SHoward Hinnant{
4173e519524SHoward Hinnant    __x.swap(__y);
4183e519524SHoward Hinnant}
4193e519524SHoward Hinnant
4203e519524SHoward Hinnanttemplate <class _Tp, size_t _Size>
421e4957601SMarshall Clowstruct _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> >
422f5ab703fSHoward Hinnant    : public integral_constant<size_t, _Size> {};
4233e519524SHoward Hinnant
4243e519524SHoward Hinnanttemplate <size_t _Ip, class _Tp, size_t _Size>
4252b0c7abbSLouis Dionnestruct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> >
4263e519524SHoward Hinnant{
4276db379a2SMarshall Clow    static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)");
4283e519524SHoward Hinnant    typedef _Tp type;
4293e519524SHoward Hinnant};
4303e519524SHoward Hinnant
4313e519524SHoward Hinnanttemplate <size_t _Ip, class _Tp, size_t _Size>
4323af48ef7SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
4333e519524SHoward Hinnant_Tp&
4348f0cd597SHoward Hinnantget(array<_Tp, _Size>& __a) _NOEXCEPT
4353e519524SHoward Hinnant{
43636a60721SMarshall Clow    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)");
4378bf1f08aSMarshall Clow    return __a.__elems_[_Ip];
4383e519524SHoward Hinnant}
4393e519524SHoward Hinnant
4403e519524SHoward Hinnanttemplate <size_t _Ip, class _Tp, size_t _Size>
4413af48ef7SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
4423e519524SHoward Hinnantconst _Tp&
4438f0cd597SHoward Hinnantget(const array<_Tp, _Size>& __a) _NOEXCEPT
4443e519524SHoward Hinnant{
44536a60721SMarshall Clow    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)");
4468bf1f08aSMarshall Clow    return __a.__elems_[_Ip];
4473e519524SHoward Hinnant}
4483e519524SHoward Hinnant
449208156e8SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
450601afb30SHoward Hinnant
451601afb30SHoward Hinnanttemplate <size_t _Ip, class _Tp, size_t _Size>
4523af48ef7SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
453601afb30SHoward Hinnant_Tp&&
4548f0cd597SHoward Hinnantget(array<_Tp, _Size>&& __a) _NOEXCEPT
455601afb30SHoward Hinnant{
45636a60721SMarshall Clow    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)");
4578bf1f08aSMarshall Clow    return _VSTD::move(__a.__elems_[_Ip]);
458601afb30SHoward Hinnant}
459601afb30SHoward Hinnant
460545b8861SEric Fiseliertemplate <size_t _Ip, class _Tp, size_t _Size>
461545b8861SEric Fiselierinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
462545b8861SEric Fiselierconst _Tp&&
463545b8861SEric Fiselierget(const array<_Tp, _Size>&& __a) _NOEXCEPT
464545b8861SEric Fiselier{
465545b8861SEric Fiselier    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)");
466545b8861SEric Fiselier    return _VSTD::move(__a.__elems_[_Ip]);
467545b8861SEric Fiselier}
468545b8861SEric Fiselier
469208156e8SEric Fiselier#endif  // !_LIBCPP_CXX03_LANG
470601afb30SHoward Hinnant
471e93e58c6SMarek Kurdej#if _LIBCPP_STD_VER > 17
472e93e58c6SMarek Kurdej
473e93e58c6SMarek Kurdejtemplate <typename _Tp, size_t _Size, size_t... _Index>
474e93e58c6SMarek Kurdej_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size>
475e93e58c6SMarek Kurdej__to_array_lvalue_impl(_Tp (&__arr)[_Size], index_sequence<_Index...>) {
476e93e58c6SMarek Kurdej  return {{__arr[_Index]...}};
477e93e58c6SMarek Kurdej}
478e93e58c6SMarek Kurdej
479e93e58c6SMarek Kurdejtemplate <typename _Tp, size_t _Size, size_t... _Index>
480e93e58c6SMarek Kurdej_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size>
481e93e58c6SMarek Kurdej__to_array_rvalue_impl(_Tp(&&__arr)[_Size], index_sequence<_Index...>) {
482e93e58c6SMarek Kurdej  return {{_VSTD::move(__arr[_Index])...}};
483e93e58c6SMarek Kurdej}
484e93e58c6SMarek Kurdej
485e93e58c6SMarek Kurdejtemplate <typename _Tp, size_t _Size>
486e93e58c6SMarek Kurdej_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size>
487e93e58c6SMarek Kurdejto_array(_Tp (&__arr)[_Size]) noexcept(is_nothrow_constructible_v<_Tp, _Tp&>) {
488e93e58c6SMarek Kurdej  static_assert(
489e93e58c6SMarek Kurdej      !is_array_v<_Tp>,
490e93e58c6SMarek Kurdej      "[array.creation]/1: to_array does not accept multidimensional arrays.");
491e93e58c6SMarek Kurdej  static_assert(
492e93e58c6SMarek Kurdej      is_constructible_v<_Tp, _Tp&>,
493e93e58c6SMarek Kurdej      "[array.creation]/1: to_array requires copy constructible elements.");
494e93e58c6SMarek Kurdej  return __to_array_lvalue_impl(__arr, make_index_sequence<_Size>());
495e93e58c6SMarek Kurdej}
496e93e58c6SMarek Kurdej
497e93e58c6SMarek Kurdejtemplate <typename _Tp, size_t _Size>
498e93e58c6SMarek Kurdej_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size>
499e93e58c6SMarek Kurdejto_array(_Tp(&&__arr)[_Size]) noexcept(is_nothrow_move_constructible_v<_Tp>) {
500e93e58c6SMarek Kurdej  static_assert(
501e93e58c6SMarek Kurdej      !is_array_v<_Tp>,
502e93e58c6SMarek Kurdej      "[array.creation]/4: to_array does not accept multidimensional arrays.");
503e93e58c6SMarek Kurdej  static_assert(
504e93e58c6SMarek Kurdej      is_move_constructible_v<_Tp>,
505e93e58c6SMarek Kurdej      "[array.creation]/4: to_array requires move constructible elements.");
506e93e58c6SMarek Kurdej  return __to_array_rvalue_impl(_VSTD::move(__arr),
507e93e58c6SMarek Kurdej                                make_index_sequence<_Size>());
508e93e58c6SMarek Kurdej}
509e93e58c6SMarek Kurdej
510e93e58c6SMarek Kurdej#endif // _LIBCPP_STD_VER > 17
511e93e58c6SMarek Kurdej
5123e519524SHoward Hinnant_LIBCPP_END_NAMESPACE_STD
5133e519524SHoward Hinnant
5143e519524SHoward Hinnant#endif  // _LIBCPP_ARRAY
515