xref: /llvm-project-15.0.7/libcxx/include/array (revision f56972e2)
13e519524SHoward Hinnant// -*- C++ -*-
23e519524SHoward Hinnant//===---------------------------- array -----------------------------------===//
33e519524SHoward Hinnant//
45b08a8a4SHoward Hinnant//                     The LLVM Compiler Infrastructure
53e519524SHoward Hinnant//
6412dbebeSHoward Hinnant// This file is dual licensed under the MIT and the University of Illinois Open
7412dbebeSHoward Hinnant// Source Licenses. See LICENSE.TXT for details.
83e519524SHoward Hinnant//
93e519524SHoward Hinnant//===----------------------------------------------------------------------===//
103e519524SHoward Hinnant
113e519524SHoward Hinnant#ifndef _LIBCPP_ARRAY
123e519524SHoward Hinnant#define _LIBCPP_ARRAY
133e519524SHoward Hinnant
143e519524SHoward Hinnant/*
153e519524SHoward Hinnant    array synopsis
163e519524SHoward Hinnant
173e519524SHoward Hinnantnamespace std
183e519524SHoward Hinnant{
193e519524SHoward Hinnanttemplate <class T, size_t N >
203e519524SHoward Hinnantstruct array
213e519524SHoward Hinnant{
223e519524SHoward Hinnant    // types:
233e519524SHoward Hinnant    typedef T & reference;
243e519524SHoward Hinnant    typedef const T & const_reference;
253e519524SHoward Hinnant    typedef implementation defined iterator;
263e519524SHoward Hinnant    typedef implementation defined const_iterator;
273e519524SHoward Hinnant    typedef size_t size_type;
283e519524SHoward Hinnant    typedef ptrdiff_t difference_type;
293e519524SHoward Hinnant    typedef T value_type;
303e519524SHoward Hinnant    typedef T* pointer;
313e519524SHoward Hinnant    typedef const T* const_pointer;
323e519524SHoward Hinnant    typedef std::reverse_iterator<iterator> reverse_iterator;
333e519524SHoward Hinnant    typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
343e519524SHoward Hinnant
353e519524SHoward Hinnant    // No explicit construct/copy/destroy for aggregate type
363e519524SHoward Hinnant    void fill(const T& u);
37f07dd8d0SEric Fiselier    void swap(array& a) noexcept(is_nothrow_swappable_v<T>);
383e519524SHoward Hinnant
393e519524SHoward Hinnant    // iterators:
408f0cd597SHoward Hinnant    iterator begin() noexcept;
418f0cd597SHoward Hinnant    const_iterator begin() const noexcept;
428f0cd597SHoward Hinnant    iterator end() noexcept;
438f0cd597SHoward Hinnant    const_iterator end() const noexcept;
443e519524SHoward Hinnant
458f0cd597SHoward Hinnant    reverse_iterator rbegin() noexcept;
468f0cd597SHoward Hinnant    const_reverse_iterator rbegin() const noexcept;
478f0cd597SHoward Hinnant    reverse_iterator rend() noexcept;
488f0cd597SHoward Hinnant    const_reverse_iterator rend() const noexcept;
493e519524SHoward Hinnant
508f0cd597SHoward Hinnant    const_iterator cbegin() const noexcept;
518f0cd597SHoward Hinnant    const_iterator cend() const noexcept;
528f0cd597SHoward Hinnant    const_reverse_iterator crbegin() const noexcept;
538f0cd597SHoward Hinnant    const_reverse_iterator crend() const noexcept;
543e519524SHoward Hinnant
553e519524SHoward Hinnant    // capacity:
568f0cd597SHoward Hinnant    constexpr size_type size() const noexcept;
578f0cd597SHoward Hinnant    constexpr size_type max_size() const noexcept;
58397717b7SHoward Hinnant    constexpr bool empty() const noexcept;
593e519524SHoward Hinnant
603e519524SHoward Hinnant    // element access:
613e519524SHoward Hinnant    reference operator[](size_type n);
628bf1f08aSMarshall Clow    const_reference operator[](size_type n) const; // constexpr in C++14
638bf1f08aSMarshall Clow    const_reference at(size_type n) const; // constexpr in C++14
643e519524SHoward Hinnant    reference at(size_type n);
653e519524SHoward Hinnant
663e519524SHoward Hinnant    reference front();
678bf1f08aSMarshall Clow    const_reference front() const; // constexpr in C++14
683e519524SHoward Hinnant    reference back();
698bf1f08aSMarshall Clow    const_reference back() const; // constexpr in C++14
703e519524SHoward Hinnant
718f0cd597SHoward Hinnant    T* data() noexcept;
728f0cd597SHoward Hinnant    const T* data() const noexcept;
733e519524SHoward Hinnant};
743e519524SHoward Hinnant
750ca8c089SMarshall Clow  template <class T, class... U>
760ca8c089SMarshall Clow    array(T, U...) -> array<T, 1 + sizeof...(U)>;
770ca8c089SMarshall Clow
783e519524SHoward Hinnanttemplate <class T, size_t N>
793e519524SHoward Hinnant  bool operator==(const array<T,N>& x, const array<T,N>& y);
803e519524SHoward Hinnanttemplate <class T, size_t N>
813e519524SHoward Hinnant  bool operator!=(const array<T,N>& x, const array<T,N>& y);
823e519524SHoward Hinnanttemplate <class T, size_t N>
833e519524SHoward Hinnant  bool operator<(const array<T,N>& x, const array<T,N>& y);
843e519524SHoward Hinnanttemplate <class T, size_t N>
853e519524SHoward Hinnant  bool operator>(const array<T,N>& x, const array<T,N>& y);
863e519524SHoward Hinnanttemplate <class T, size_t N>
873e519524SHoward Hinnant  bool operator<=(const array<T,N>& x, const array<T,N>& y);
883e519524SHoward Hinnanttemplate <class T, size_t N>
893e519524SHoward Hinnant  bool operator>=(const array<T,N>& x, const array<T,N>& y);
903e519524SHoward Hinnant
913e519524SHoward Hinnanttemplate <class T, size_t N >
920ca8c089SMarshall Clow  void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y))); // C++17
933e519524SHoward Hinnant
943e519524SHoward Hinnanttemplate <class T> class tuple_size;
955fcc8169SMarshall Clowtemplate <size_t I, class T> class tuple_element;
963e519524SHoward Hinnanttemplate <class T, size_t N> struct tuple_size<array<T, N>>;
975fcc8169SMarshall Clowtemplate <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>;
985fcc8169SMarshall Clowtemplate <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14
995fcc8169SMarshall Clowtemplate <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++14
1005fcc8169SMarshall Clowtemplate <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14
101545b8861SEric Fiseliertemplate <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14
1023e519524SHoward Hinnant
1033e519524SHoward Hinnant}  // std
1043e519524SHoward Hinnant
1053e519524SHoward Hinnant*/
1063e519524SHoward Hinnant
1073e519524SHoward Hinnant#include <__config>
1083e519524SHoward Hinnant#include <__tuple>
1093e519524SHoward Hinnant#include <type_traits>
1103e519524SHoward Hinnant#include <utility>
1113e519524SHoward Hinnant#include <iterator>
1123e519524SHoward Hinnant#include <algorithm>
1133e519524SHoward Hinnant#include <stdexcept>
11459cdf90aSEric Fiselier#include <cstdlib> // for _LIBCPP_UNREACHABLE
115*f56972e2SMarshall Clow#include <version>
11659cdf90aSEric Fiselier#include <__debug>
1173e519524SHoward Hinnant
118073458b1SHoward Hinnant#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1193e519524SHoward Hinnant#pragma GCC system_header
120073458b1SHoward Hinnant#endif
1213e519524SHoward Hinnant
122a016efb1SEric Fiselier
123a016efb1SEric Fiselier
1243e519524SHoward Hinnant_LIBCPP_BEGIN_NAMESPACE_STD
1253e519524SHoward Hinnant
12659cdf90aSEric Fiselier
1273e519524SHoward Hinnanttemplate <class _Tp, size_t _Size>
128e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS array
1293e519524SHoward Hinnant{
1303e519524SHoward Hinnant    // types:
1313e519524SHoward Hinnant    typedef array __self;
1323e519524SHoward Hinnant    typedef _Tp                                   value_type;
1333e519524SHoward Hinnant    typedef value_type&                           reference;
1343e519524SHoward Hinnant    typedef const value_type&                     const_reference;
1353e519524SHoward Hinnant    typedef value_type*                           iterator;
1363e519524SHoward Hinnant    typedef const value_type*                     const_iterator;
1373e519524SHoward Hinnant    typedef value_type*                           pointer;
1383e519524SHoward Hinnant    typedef const value_type*                     const_pointer;
1393e519524SHoward Hinnant    typedef size_t                                size_type;
1403e519524SHoward Hinnant    typedef ptrdiff_t                             difference_type;
1413e519524SHoward Hinnant    typedef std::reverse_iterator<iterator>       reverse_iterator;
1423e519524SHoward Hinnant    typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
1433e519524SHoward Hinnant
14459cdf90aSEric Fiselier    _Tp __elems_[_Size];
1453e519524SHoward Hinnant
1463e519524SHoward Hinnant    // No explicit construct/copy/destroy for aggregate type
14759cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY void fill(const value_type& __u) {
14859cdf90aSEric Fiselier      _VSTD::fill_n(__elems_, _Size, __u);
14959cdf90aSEric Fiselier    }
150afeda5c2SEric Fiselier
1518f0cd597SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
15259cdf90aSEric Fiselier    void swap(array& __a) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) {
15359cdf90aSEric Fiselier      std::swap_ranges(__elems_, __elems_ + _Size, __a.__elems_);
15459cdf90aSEric Fiselier    }
1553e519524SHoward Hinnant
1563e519524SHoward Hinnant    // iterators:
157020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
15859cdf90aSEric Fiselier    iterator begin() _NOEXCEPT {return iterator(data());}
159020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16059cdf90aSEric Fiselier    const_iterator begin() const _NOEXCEPT {return const_iterator(data());}
161020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16259cdf90aSEric Fiselier    iterator end() _NOEXCEPT {return iterator(data() + _Size);}
163020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16459cdf90aSEric Fiselier    const_iterator end() const _NOEXCEPT {return const_iterator(data() + _Size);}
1653e519524SHoward Hinnant
166020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1678f0cd597SHoward Hinnant    reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
168020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1698f0cd597SHoward Hinnant    const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
170020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1718f0cd597SHoward Hinnant    reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
172020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1738f0cd597SHoward Hinnant    const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
1743e519524SHoward Hinnant
175020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1768f0cd597SHoward Hinnant    const_iterator cbegin() const _NOEXCEPT {return begin();}
177020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1788f0cd597SHoward Hinnant    const_iterator cend() const _NOEXCEPT {return end();}
179020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1808f0cd597SHoward Hinnant    const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
181020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1828f0cd597SHoward Hinnant    const_reverse_iterator crend() const _NOEXCEPT {return rend();}
1833e519524SHoward Hinnant
1843e519524SHoward Hinnant    // capacity:
1858f0cd597SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
186397717b7SHoward Hinnant    _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;}
1878f0cd597SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
188397717b7SHoward Hinnant    _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;}
18972c8fad4SMarshall Clow    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
19059cdf90aSEric Fiselier    _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return false; }
1913e519524SHoward Hinnant
1923e519524SHoward Hinnant    // element access:
193e7826950SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
194e7826950SMarshall Clow    reference operator[](size_type __n)             {return __elems_[__n];}
195e7826950SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
196e7826950SMarshall Clow    const_reference operator[](size_type __n) const {return __elems_[__n];}
197e7826950SMarshall Clow
198e7826950SMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX14       reference at(size_type __n);
1998bf1f08aSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const;
2003e519524SHoward Hinnant
201e7826950SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front()             {return __elems_[0];}
2028bf1f08aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const {return __elems_[0];}
20359cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back()              {return __elems_[_Size - 1];}
20459cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const  {return __elems_[_Size - 1];}
2053e519524SHoward Hinnant
206020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
207936ff584SNirav Dave    value_type* data() _NOEXCEPT {return __elems_;}
208020b623aSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
209936ff584SNirav Dave    const value_type* data() const _NOEXCEPT {return __elems_;}
2103e519524SHoward Hinnant};
2113e519524SHoward Hinnant
21259cdf90aSEric Fiselier
2133e519524SHoward Hinnanttemplate <class _Tp, size_t _Size>
214e7826950SMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX14
2153e519524SHoward Hinnanttypename array<_Tp, _Size>::reference
2163e519524SHoward Hinnantarray<_Tp, _Size>::at(size_type __n)
2173e519524SHoward Hinnant{
2183e519524SHoward Hinnant    if (__n >= _Size)
219d437fa5cSMarshall Clow        __throw_out_of_range("array::at");
220d437fa5cSMarshall Clow
2213e519524SHoward Hinnant    return __elems_[__n];
2223e519524SHoward Hinnant}
2233e519524SHoward Hinnant
2243e519524SHoward Hinnanttemplate <class _Tp, size_t _Size>
2258bf1f08aSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11
2263e519524SHoward Hinnanttypename array<_Tp, _Size>::const_reference
2273e519524SHoward Hinnantarray<_Tp, _Size>::at(size_type __n) const
2283e519524SHoward Hinnant{
2293e519524SHoward Hinnant    if (__n >= _Size)
230d437fa5cSMarshall Clow        __throw_out_of_range("array::at");
2313e519524SHoward Hinnant    return __elems_[__n];
2323e519524SHoward Hinnant}
2333e519524SHoward Hinnant
23459cdf90aSEric Fiseliertemplate <class _Tp>
23559cdf90aSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS array<_Tp, 0>
23659cdf90aSEric Fiselier{
23759cdf90aSEric Fiselier    // types:
23859cdf90aSEric Fiselier    typedef array __self;
23959cdf90aSEric Fiselier    typedef _Tp                                   value_type;
24059cdf90aSEric Fiselier    typedef value_type&                           reference;
24159cdf90aSEric Fiselier    typedef const value_type&                     const_reference;
24259cdf90aSEric Fiselier    typedef value_type*                           iterator;
24359cdf90aSEric Fiselier    typedef const value_type*                     const_iterator;
24459cdf90aSEric Fiselier    typedef value_type*                           pointer;
24559cdf90aSEric Fiselier    typedef const value_type*                     const_pointer;
24659cdf90aSEric Fiselier    typedef size_t                                size_type;
24759cdf90aSEric Fiselier    typedef ptrdiff_t                             difference_type;
24859cdf90aSEric Fiselier    typedef std::reverse_iterator<iterator>       reverse_iterator;
24959cdf90aSEric Fiselier    typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
25059cdf90aSEric Fiselier
25159cdf90aSEric Fiselier    typedef typename conditional<is_const<_Tp>::value, const char,
25259cdf90aSEric Fiselier                                char>::type _CharType;
2531a78ae3cSEric Fiselier
2541a78ae3cSEric Fiselier    struct  _ArrayInStructT { _Tp __data_[1]; };
2551a78ae3cSEric Fiselier    _ALIGNAS_TYPE(_ArrayInStructT) _CharType __elems_[sizeof(_ArrayInStructT)];
25659cdf90aSEric Fiselier
25759cdf90aSEric Fiselier    // No explicit construct/copy/destroy for aggregate type
25859cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY void fill(const value_type&) {
25959cdf90aSEric Fiselier      static_assert(!is_const<_Tp>::value,
26059cdf90aSEric Fiselier                    "cannot fill zero-sized array of type 'const T'");
26159cdf90aSEric Fiselier    }
26259cdf90aSEric Fiselier
26359cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
26459cdf90aSEric Fiselier    void swap(array&) _NOEXCEPT {
26559cdf90aSEric Fiselier      static_assert(!is_const<_Tp>::value,
26659cdf90aSEric Fiselier                    "cannot swap zero-sized array of type 'const T'");
26759cdf90aSEric Fiselier    }
26859cdf90aSEric Fiselier
26959cdf90aSEric Fiselier    // iterators:
27059cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
27159cdf90aSEric Fiselier    iterator begin() _NOEXCEPT {return iterator(data());}
27259cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
27359cdf90aSEric Fiselier    const_iterator begin() const _NOEXCEPT {return const_iterator(data());}
27459cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
27559cdf90aSEric Fiselier    iterator end() _NOEXCEPT {return iterator(data());}
27659cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
27759cdf90aSEric Fiselier    const_iterator end() const _NOEXCEPT {return const_iterator(data());}
27859cdf90aSEric Fiselier
27959cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
28059cdf90aSEric Fiselier    reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
28159cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
28259cdf90aSEric Fiselier    const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
28359cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
28459cdf90aSEric Fiselier    reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
28559cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
28659cdf90aSEric Fiselier    const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
28759cdf90aSEric Fiselier
28859cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
28959cdf90aSEric Fiselier    const_iterator cbegin() const _NOEXCEPT {return begin();}
29059cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
29159cdf90aSEric Fiselier    const_iterator cend() const _NOEXCEPT {return end();}
29259cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
29359cdf90aSEric Fiselier    const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
29459cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
29559cdf90aSEric Fiselier    const_reverse_iterator crend() const _NOEXCEPT {return rend();}
29659cdf90aSEric Fiselier
29759cdf90aSEric Fiselier    // capacity:
29859cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
29959cdf90aSEric Fiselier    _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return 0; }
30059cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
30159cdf90aSEric Fiselier    _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return 0;}
30259cdf90aSEric Fiselier    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
30359cdf90aSEric Fiselier    _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return true;}
30459cdf90aSEric Fiselier
30559cdf90aSEric Fiselier    // element access:
30659cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
30759cdf90aSEric Fiselier    reference operator[](size_type) {
30859cdf90aSEric Fiselier      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
30959cdf90aSEric Fiselier      _LIBCPP_UNREACHABLE();
31059cdf90aSEric Fiselier    }
31159cdf90aSEric Fiselier
31259cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
31359cdf90aSEric Fiselier    const_reference operator[](size_type) const {
31459cdf90aSEric Fiselier      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
31559cdf90aSEric Fiselier      _LIBCPP_UNREACHABLE();
31659cdf90aSEric Fiselier    }
31759cdf90aSEric Fiselier
31859cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
31959cdf90aSEric Fiselier    reference at(size_type) {
32059cdf90aSEric Fiselier      __throw_out_of_range("array<T, 0>::at");
32159cdf90aSEric Fiselier      _LIBCPP_UNREACHABLE();
32259cdf90aSEric Fiselier    }
32359cdf90aSEric Fiselier
32459cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
32559cdf90aSEric Fiselier    const_reference at(size_type) const {
32659cdf90aSEric Fiselier      __throw_out_of_range("array<T, 0>::at");
32759cdf90aSEric Fiselier      _LIBCPP_UNREACHABLE();
32859cdf90aSEric Fiselier    }
32959cdf90aSEric Fiselier
33059cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
33159cdf90aSEric Fiselier    reference front() {
33259cdf90aSEric Fiselier      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
33359cdf90aSEric Fiselier      _LIBCPP_UNREACHABLE();
33459cdf90aSEric Fiselier    }
33559cdf90aSEric Fiselier
33659cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
33759cdf90aSEric Fiselier    const_reference front() const {
33859cdf90aSEric Fiselier      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
33959cdf90aSEric Fiselier      _LIBCPP_UNREACHABLE();
34059cdf90aSEric Fiselier    }
34159cdf90aSEric Fiselier
34259cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
34359cdf90aSEric Fiselier    reference back() {
34459cdf90aSEric Fiselier      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
34559cdf90aSEric Fiselier      _LIBCPP_UNREACHABLE();
34659cdf90aSEric Fiselier    }
34759cdf90aSEric Fiselier
34859cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
34959cdf90aSEric Fiselier    const_reference back() const {
35059cdf90aSEric Fiselier      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
35159cdf90aSEric Fiselier      _LIBCPP_UNREACHABLE();
35259cdf90aSEric Fiselier    }
35359cdf90aSEric Fiselier
35459cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
35559cdf90aSEric Fiselier    value_type* data() _NOEXCEPT {return reinterpret_cast<value_type*>(__elems_);}
35659cdf90aSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
35759cdf90aSEric Fiselier    const value_type* data() const _NOEXCEPT {return reinterpret_cast<const value_type*>(__elems_);}
35859cdf90aSEric Fiselier};
35959cdf90aSEric Fiselier
36059cdf90aSEric Fiselier
3610ca8c089SMarshall Clow#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
3620ca8c089SMarshall Clowtemplate<class _Tp, class... _Args,
3630ca8c089SMarshall Clow         class = typename enable_if<(is_same_v<_Tp, _Args> && ...), void>::type
3640ca8c089SMarshall Clow         >
3650ca8c089SMarshall Clowarray(_Tp, _Args...)
3660ca8c089SMarshall Clow  -> array<_Tp, 1 + sizeof...(_Args)>;
3670ca8c089SMarshall Clow#endif
3680ca8c089SMarshall Clow
3693e519524SHoward Hinnanttemplate <class _Tp, size_t _Size>
3703af48ef7SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
37107d8ac0aSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
3723e519524SHoward Hinnantoperator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
3733e519524SHoward Hinnant{
37459cdf90aSEric Fiselier    return _VSTD::equal(__x.begin(), __x.end(), __y.begin());
3753e519524SHoward Hinnant}
3763e519524SHoward Hinnant
3773e519524SHoward Hinnanttemplate <class _Tp, size_t _Size>
3783af48ef7SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
37907d8ac0aSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
3803e519524SHoward Hinnantoperator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
3813e519524SHoward Hinnant{
3823e519524SHoward Hinnant    return !(__x == __y);
3833e519524SHoward Hinnant}
3843e519524SHoward Hinnant
3853e519524SHoward Hinnanttemplate <class _Tp, size_t _Size>
3863af48ef7SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
38707d8ac0aSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
3883e519524SHoward Hinnantoperator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
3893e519524SHoward Hinnant{
39059cdf90aSEric Fiselier    return _VSTD::lexicographical_compare(__x.begin(), __x.end(),
39159cdf90aSEric Fiselier                                          __y.begin(), __y.end());
3923e519524SHoward Hinnant}
3933e519524SHoward Hinnant
3943e519524SHoward Hinnanttemplate <class _Tp, size_t _Size>
3953af48ef7SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
39607d8ac0aSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
3973e519524SHoward Hinnantoperator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
3983e519524SHoward Hinnant{
3993e519524SHoward Hinnant    return __y < __x;
4003e519524SHoward Hinnant}
4013e519524SHoward Hinnant
4023e519524SHoward Hinnanttemplate <class _Tp, size_t _Size>
4033af48ef7SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
40407d8ac0aSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
4053e519524SHoward Hinnantoperator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
4063e519524SHoward Hinnant{
4073e519524SHoward Hinnant    return !(__y < __x);
4083e519524SHoward Hinnant}
4093e519524SHoward Hinnant
4103e519524SHoward Hinnanttemplate <class _Tp, size_t _Size>
4113af48ef7SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
41207d8ac0aSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
4133e519524SHoward Hinnantoperator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
4143e519524SHoward Hinnant{
4153e519524SHoward Hinnant    return !(__x < __y);
4163e519524SHoward Hinnant}
4173e519524SHoward Hinnant
4183e519524SHoward Hinnanttemplate <class _Tp, size_t _Size>
4193af48ef7SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
420bc95cf0dSHoward Hinnanttypename enable_if
421bc95cf0dSHoward Hinnant<
422f07dd8d0SEric Fiselier    _Size == 0 ||
423bc95cf0dSHoward Hinnant    __is_swappable<_Tp>::value,
4243e519524SHoward Hinnant    void
425bc95cf0dSHoward Hinnant>::type
426ee66eb13SMarshall Clowswap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y)
427f07dd8d0SEric Fiselier                                  _NOEXCEPT_(noexcept(__x.swap(__y)))
4283e519524SHoward Hinnant{
4293e519524SHoward Hinnant    __x.swap(__y);
4303e519524SHoward Hinnant}
4313e519524SHoward Hinnant
4323e519524SHoward Hinnanttemplate <class _Tp, size_t _Size>
433e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> >
434f5ab703fSHoward Hinnant    : public integral_constant<size_t, _Size> {};
4353e519524SHoward Hinnant
4363e519524SHoward Hinnanttemplate <size_t _Ip, class _Tp, size_t _Size>
437e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> >
4383e519524SHoward Hinnant{
4396db379a2SMarshall Clow    static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)");
4403e519524SHoward Hinnantpublic:
4413e519524SHoward Hinnant    typedef _Tp type;
4423e519524SHoward Hinnant};
4433e519524SHoward Hinnant
4443e519524SHoward Hinnanttemplate <size_t _Ip, class _Tp, size_t _Size>
4453af48ef7SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
4463e519524SHoward Hinnant_Tp&
4478f0cd597SHoward Hinnantget(array<_Tp, _Size>& __a) _NOEXCEPT
4483e519524SHoward Hinnant{
44936a60721SMarshall Clow    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)");
4508bf1f08aSMarshall Clow    return __a.__elems_[_Ip];
4513e519524SHoward Hinnant}
4523e519524SHoward Hinnant
4533e519524SHoward Hinnanttemplate <size_t _Ip, class _Tp, size_t _Size>
4543af48ef7SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
4553e519524SHoward Hinnantconst _Tp&
4568f0cd597SHoward Hinnantget(const array<_Tp, _Size>& __a) _NOEXCEPT
4573e519524SHoward Hinnant{
45836a60721SMarshall Clow    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)");
4598bf1f08aSMarshall Clow    return __a.__elems_[_Ip];
4603e519524SHoward Hinnant}
4613e519524SHoward Hinnant
462208156e8SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
463601afb30SHoward Hinnant
464601afb30SHoward Hinnanttemplate <size_t _Ip, class _Tp, size_t _Size>
4653af48ef7SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
466601afb30SHoward Hinnant_Tp&&
4678f0cd597SHoward Hinnantget(array<_Tp, _Size>&& __a) _NOEXCEPT
468601afb30SHoward Hinnant{
46936a60721SMarshall Clow    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)");
4708bf1f08aSMarshall Clow    return _VSTD::move(__a.__elems_[_Ip]);
471601afb30SHoward Hinnant}
472601afb30SHoward Hinnant
473545b8861SEric Fiseliertemplate <size_t _Ip, class _Tp, size_t _Size>
474545b8861SEric Fiselierinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
475545b8861SEric Fiselierconst _Tp&&
476545b8861SEric Fiselierget(const array<_Tp, _Size>&& __a) _NOEXCEPT
477545b8861SEric Fiselier{
478545b8861SEric Fiselier    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)");
479545b8861SEric Fiselier    return _VSTD::move(__a.__elems_[_Ip]);
480545b8861SEric Fiselier}
481545b8861SEric Fiselier
482208156e8SEric Fiselier#endif  // !_LIBCPP_CXX03_LANG
483601afb30SHoward Hinnant
4843e519524SHoward Hinnant_LIBCPP_END_NAMESPACE_STD
4853e519524SHoward Hinnant
4863e519524SHoward Hinnant#endif  // _LIBCPP_ARRAY
487