xref: /freebsd/contrib/llvm-project/libcxx/include/array (revision 62cfcf62f627e5093fb37026a6d8c98e4d2ef04c)
10b57cec5SDimitry Andric// -*- C++ -*-
20b57cec5SDimitry Andric//===---------------------------- array -----------------------------------===//
30b57cec5SDimitry Andric//
40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric//
80b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
90b57cec5SDimitry Andric
100b57cec5SDimitry Andric#ifndef _LIBCPP_ARRAY
110b57cec5SDimitry Andric#define _LIBCPP_ARRAY
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric/*
140b57cec5SDimitry Andric    array synopsis
150b57cec5SDimitry Andric
160b57cec5SDimitry Andricnamespace std
170b57cec5SDimitry Andric{
180b57cec5SDimitry Andrictemplate <class T, size_t N >
190b57cec5SDimitry Andricstruct array
200b57cec5SDimitry Andric{
210b57cec5SDimitry Andric    // types:
220b57cec5SDimitry Andric    typedef T & reference;
230b57cec5SDimitry Andric    typedef const T & const_reference;
240b57cec5SDimitry Andric    typedef implementation defined iterator;
250b57cec5SDimitry Andric    typedef implementation defined const_iterator;
260b57cec5SDimitry Andric    typedef size_t size_type;
270b57cec5SDimitry Andric    typedef ptrdiff_t difference_type;
280b57cec5SDimitry Andric    typedef T value_type;
290b57cec5SDimitry Andric    typedef T* pointer;
300b57cec5SDimitry Andric    typedef const T* const_pointer;
310b57cec5SDimitry Andric    typedef std::reverse_iterator<iterator> reverse_iterator;
320b57cec5SDimitry Andric    typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
330b57cec5SDimitry Andric
340b57cec5SDimitry Andric    // No explicit construct/copy/destroy for aggregate type
350b57cec5SDimitry Andric    void fill(const T& u);
360b57cec5SDimitry Andric    void swap(array& a) noexcept(is_nothrow_swappable_v<T>);
370b57cec5SDimitry Andric
380b57cec5SDimitry Andric    // iterators:
390b57cec5SDimitry Andric    iterator begin() noexcept;
400b57cec5SDimitry Andric    const_iterator begin() const noexcept;
410b57cec5SDimitry Andric    iterator end() noexcept;
420b57cec5SDimitry Andric    const_iterator end() const noexcept;
430b57cec5SDimitry Andric
440b57cec5SDimitry Andric    reverse_iterator rbegin() noexcept;
450b57cec5SDimitry Andric    const_reverse_iterator rbegin() const noexcept;
460b57cec5SDimitry Andric    reverse_iterator rend() noexcept;
470b57cec5SDimitry Andric    const_reverse_iterator rend() const noexcept;
480b57cec5SDimitry Andric
490b57cec5SDimitry Andric    const_iterator cbegin() const noexcept;
500b57cec5SDimitry Andric    const_iterator cend() const noexcept;
510b57cec5SDimitry Andric    const_reverse_iterator crbegin() const noexcept;
520b57cec5SDimitry Andric    const_reverse_iterator crend() const noexcept;
530b57cec5SDimitry Andric
540b57cec5SDimitry Andric    // capacity:
550b57cec5SDimitry Andric    constexpr size_type size() const noexcept;
560b57cec5SDimitry Andric    constexpr size_type max_size() const noexcept;
570b57cec5SDimitry Andric    constexpr bool empty() const noexcept;
580b57cec5SDimitry Andric
590b57cec5SDimitry Andric    // element access:
600b57cec5SDimitry Andric    reference operator[](size_type n);
610b57cec5SDimitry Andric    const_reference operator[](size_type n) const; // constexpr in C++14
620b57cec5SDimitry Andric    const_reference at(size_type n) const; // constexpr in C++14
630b57cec5SDimitry Andric    reference at(size_type n);
640b57cec5SDimitry Andric
650b57cec5SDimitry Andric    reference front();
660b57cec5SDimitry Andric    const_reference front() const; // constexpr in C++14
670b57cec5SDimitry Andric    reference back();
680b57cec5SDimitry Andric    const_reference back() const; // constexpr in C++14
690b57cec5SDimitry Andric
700b57cec5SDimitry Andric    T* data() noexcept;
710b57cec5SDimitry Andric    const T* data() const noexcept;
720b57cec5SDimitry Andric};
730b57cec5SDimitry Andric
740b57cec5SDimitry Andric  template <class T, class... U>
750b57cec5SDimitry Andric    array(T, U...) -> array<T, 1 + sizeof...(U)>;
760b57cec5SDimitry Andric
770b57cec5SDimitry Andrictemplate <class T, size_t N>
780b57cec5SDimitry Andric  bool operator==(const array<T,N>& x, const array<T,N>& y);
790b57cec5SDimitry Andrictemplate <class T, size_t N>
800b57cec5SDimitry Andric  bool operator!=(const array<T,N>& x, const array<T,N>& y);
810b57cec5SDimitry Andrictemplate <class T, size_t N>
820b57cec5SDimitry Andric  bool operator<(const array<T,N>& x, const array<T,N>& y);
830b57cec5SDimitry Andrictemplate <class T, size_t N>
840b57cec5SDimitry Andric  bool operator>(const array<T,N>& x, const array<T,N>& y);
850b57cec5SDimitry Andrictemplate <class T, size_t N>
860b57cec5SDimitry Andric  bool operator<=(const array<T,N>& x, const array<T,N>& y);
870b57cec5SDimitry Andrictemplate <class T, size_t N>
880b57cec5SDimitry Andric  bool operator>=(const array<T,N>& x, const array<T,N>& y);
890b57cec5SDimitry Andric
900b57cec5SDimitry Andrictemplate <class T, size_t N >
910b57cec5SDimitry Andric  void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y))); // C++17
920b57cec5SDimitry Andric
930b57cec5SDimitry Andrictemplate <class T> struct tuple_size;
940b57cec5SDimitry Andrictemplate <size_t I, class T> struct tuple_element;
950b57cec5SDimitry Andrictemplate <class T, size_t N> struct tuple_size<array<T, N>>;
960b57cec5SDimitry Andrictemplate <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>;
970b57cec5SDimitry Andrictemplate <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14
980b57cec5SDimitry Andrictemplate <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++14
990b57cec5SDimitry Andrictemplate <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14
1000b57cec5SDimitry Andrictemplate <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14
1010b57cec5SDimitry Andric
1020b57cec5SDimitry Andric}  // std
1030b57cec5SDimitry Andric
1040b57cec5SDimitry Andric*/
1050b57cec5SDimitry Andric
1060b57cec5SDimitry Andric#include <__config>
1070b57cec5SDimitry Andric#include <__tuple>
1080b57cec5SDimitry Andric#include <type_traits>
1090b57cec5SDimitry Andric#include <utility>
1100b57cec5SDimitry Andric#include <iterator>
1110b57cec5SDimitry Andric#include <algorithm>
1120b57cec5SDimitry Andric#include <stdexcept>
1130b57cec5SDimitry Andric#include <cstdlib> // for _LIBCPP_UNREACHABLE
1140b57cec5SDimitry Andric#include <version>
1150b57cec5SDimitry Andric#include <__debug>
1160b57cec5SDimitry Andric
1170b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1180b57cec5SDimitry Andric#pragma GCC system_header
1190b57cec5SDimitry Andric#endif
1200b57cec5SDimitry Andric
1210b57cec5SDimitry Andric
1220b57cec5SDimitry Andric
1230b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
1240b57cec5SDimitry Andric
1250b57cec5SDimitry Andric
1260b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size>
1270b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS array
1280b57cec5SDimitry Andric{
1290b57cec5SDimitry Andric    // types:
1300b57cec5SDimitry Andric    typedef array __self;
1310b57cec5SDimitry Andric    typedef _Tp                                   value_type;
1320b57cec5SDimitry Andric    typedef value_type&                           reference;
1330b57cec5SDimitry Andric    typedef const value_type&                     const_reference;
1340b57cec5SDimitry Andric    typedef value_type*                           iterator;
1350b57cec5SDimitry Andric    typedef const value_type*                     const_iterator;
1360b57cec5SDimitry Andric    typedef value_type*                           pointer;
1370b57cec5SDimitry Andric    typedef const value_type*                     const_pointer;
1380b57cec5SDimitry Andric    typedef size_t                                size_type;
1390b57cec5SDimitry Andric    typedef ptrdiff_t                             difference_type;
1400b57cec5SDimitry Andric    typedef std::reverse_iterator<iterator>       reverse_iterator;
1410b57cec5SDimitry Andric    typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
1420b57cec5SDimitry Andric
1430b57cec5SDimitry Andric    _Tp __elems_[_Size];
1440b57cec5SDimitry Andric
1450b57cec5SDimitry Andric    // No explicit construct/copy/destroy for aggregate type
1460b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void fill(const value_type& __u) {
1470b57cec5SDimitry Andric      _VSTD::fill_n(__elems_, _Size, __u);
1480b57cec5SDimitry Andric    }
1490b57cec5SDimitry Andric
1500b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1510b57cec5SDimitry Andric    void swap(array& __a) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) {
1520b57cec5SDimitry Andric      std::swap_ranges(__elems_, __elems_ + _Size, __a.__elems_);
1530b57cec5SDimitry Andric    }
1540b57cec5SDimitry Andric
1550b57cec5SDimitry Andric    // iterators:
1560b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1570b57cec5SDimitry Andric    iterator begin() _NOEXCEPT {return iterator(data());}
1580b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1590b57cec5SDimitry Andric    const_iterator begin() const _NOEXCEPT {return const_iterator(data());}
1600b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1610b57cec5SDimitry Andric    iterator end() _NOEXCEPT {return iterator(data() + _Size);}
1620b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1630b57cec5SDimitry Andric    const_iterator end() const _NOEXCEPT {return const_iterator(data() + _Size);}
1640b57cec5SDimitry Andric
1650b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1660b57cec5SDimitry Andric    reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
1670b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1680b57cec5SDimitry Andric    const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
1690b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1700b57cec5SDimitry Andric    reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
1710b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1720b57cec5SDimitry Andric    const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
1730b57cec5SDimitry Andric
1740b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1750b57cec5SDimitry Andric    const_iterator cbegin() const _NOEXCEPT {return begin();}
1760b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1770b57cec5SDimitry Andric    const_iterator cend() const _NOEXCEPT {return end();}
1780b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1790b57cec5SDimitry Andric    const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
1800b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1810b57cec5SDimitry Andric    const_reverse_iterator crend() const _NOEXCEPT {return rend();}
1820b57cec5SDimitry Andric
1830b57cec5SDimitry Andric    // capacity:
1840b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1850b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;}
1860b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1870b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;}
1880b57cec5SDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1890b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return false; }
1900b57cec5SDimitry Andric
1910b57cec5SDimitry Andric    // element access:
1920b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1930b57cec5SDimitry Andric    reference operator[](size_type __n)             _NOEXCEPT {return __elems_[__n];}
1940b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1950b57cec5SDimitry Andric    const_reference operator[](size_type __n) const _NOEXCEPT {return __elems_[__n];}
1960b57cec5SDimitry Andric
1970b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX14       reference at(size_type __n);
1980b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const;
1990b57cec5SDimitry Andric
2000b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front()             _NOEXCEPT {return __elems_[0];}
2010b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const _NOEXCEPT {return __elems_[0];}
2020b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back()              _NOEXCEPT {return __elems_[_Size - 1];}
2030b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const  _NOEXCEPT {return __elems_[_Size - 1];}
2040b57cec5SDimitry Andric
2050b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2060b57cec5SDimitry Andric    value_type* data() _NOEXCEPT {return __elems_;}
2070b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2080b57cec5SDimitry Andric    const value_type* data() const _NOEXCEPT {return __elems_;}
2090b57cec5SDimitry Andric};
2100b57cec5SDimitry Andric
2110b57cec5SDimitry Andric
2120b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size>
2130b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX14
2140b57cec5SDimitry Andrictypename array<_Tp, _Size>::reference
2150b57cec5SDimitry Andricarray<_Tp, _Size>::at(size_type __n)
2160b57cec5SDimitry Andric{
2170b57cec5SDimitry Andric    if (__n >= _Size)
2180b57cec5SDimitry Andric        __throw_out_of_range("array::at");
2190b57cec5SDimitry Andric
2200b57cec5SDimitry Andric    return __elems_[__n];
2210b57cec5SDimitry Andric}
2220b57cec5SDimitry Andric
2230b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size>
2240b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX11
2250b57cec5SDimitry Andrictypename array<_Tp, _Size>::const_reference
2260b57cec5SDimitry Andricarray<_Tp, _Size>::at(size_type __n) const
2270b57cec5SDimitry Andric{
2280b57cec5SDimitry Andric    if (__n >= _Size)
2290b57cec5SDimitry Andric        __throw_out_of_range("array::at");
2300b57cec5SDimitry Andric    return __elems_[__n];
2310b57cec5SDimitry Andric}
2320b57cec5SDimitry Andric
2330b57cec5SDimitry Andrictemplate <class _Tp>
2340b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS array<_Tp, 0>
2350b57cec5SDimitry Andric{
2360b57cec5SDimitry Andric    // types:
2370b57cec5SDimitry Andric    typedef array __self;
2380b57cec5SDimitry Andric    typedef _Tp                                   value_type;
2390b57cec5SDimitry Andric    typedef value_type&                           reference;
2400b57cec5SDimitry Andric    typedef const value_type&                     const_reference;
2410b57cec5SDimitry Andric    typedef value_type*                           iterator;
2420b57cec5SDimitry Andric    typedef const value_type*                     const_iterator;
2430b57cec5SDimitry Andric    typedef value_type*                           pointer;
2440b57cec5SDimitry Andric    typedef const value_type*                     const_pointer;
2450b57cec5SDimitry Andric    typedef size_t                                size_type;
2460b57cec5SDimitry Andric    typedef ptrdiff_t                             difference_type;
2470b57cec5SDimitry Andric    typedef std::reverse_iterator<iterator>       reverse_iterator;
2480b57cec5SDimitry Andric    typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
2490b57cec5SDimitry Andric
2500b57cec5SDimitry Andric    typedef typename conditional<is_const<_Tp>::value, const char,
2510b57cec5SDimitry Andric                                char>::type _CharType;
2520b57cec5SDimitry Andric
2530b57cec5SDimitry Andric    struct  _ArrayInStructT { _Tp __data_[1]; };
2540b57cec5SDimitry Andric    _ALIGNAS_TYPE(_ArrayInStructT) _CharType __elems_[sizeof(_ArrayInStructT)];
2550b57cec5SDimitry Andric
2560b57cec5SDimitry Andric    // No explicit construct/copy/destroy for aggregate type
2570b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void fill(const value_type&) {
2580b57cec5SDimitry Andric      static_assert(!is_const<_Tp>::value,
2590b57cec5SDimitry Andric                    "cannot fill zero-sized array of type 'const T'");
2600b57cec5SDimitry Andric    }
2610b57cec5SDimitry Andric
2620b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2630b57cec5SDimitry Andric    void swap(array&) _NOEXCEPT {
2640b57cec5SDimitry Andric      static_assert(!is_const<_Tp>::value,
2650b57cec5SDimitry Andric                    "cannot swap zero-sized array of type 'const T'");
2660b57cec5SDimitry Andric    }
2670b57cec5SDimitry Andric
2680b57cec5SDimitry Andric    // iterators:
2690b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2700b57cec5SDimitry Andric    iterator begin() _NOEXCEPT {return iterator(data());}
2710b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2720b57cec5SDimitry Andric    const_iterator begin() const _NOEXCEPT {return const_iterator(data());}
2730b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2740b57cec5SDimitry Andric    iterator end() _NOEXCEPT {return iterator(data());}
2750b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2760b57cec5SDimitry Andric    const_iterator end() const _NOEXCEPT {return const_iterator(data());}
2770b57cec5SDimitry Andric
2780b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2790b57cec5SDimitry Andric    reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
2800b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2810b57cec5SDimitry Andric    const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
2820b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2830b57cec5SDimitry Andric    reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
2840b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2850b57cec5SDimitry Andric    const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
2860b57cec5SDimitry Andric
2870b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2880b57cec5SDimitry Andric    const_iterator cbegin() const _NOEXCEPT {return begin();}
2890b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2900b57cec5SDimitry Andric    const_iterator cend() const _NOEXCEPT {return end();}
2910b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2920b57cec5SDimitry Andric    const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
2930b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2940b57cec5SDimitry Andric    const_reverse_iterator crend() const _NOEXCEPT {return rend();}
2950b57cec5SDimitry Andric
2960b57cec5SDimitry Andric    // capacity:
2970b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2980b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return 0; }
2990b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3000b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return 0;}
3010b57cec5SDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
3020b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return true;}
3030b57cec5SDimitry Andric
3040b57cec5SDimitry Andric    // element access:
3050b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3060b57cec5SDimitry Andric    reference operator[](size_type) _NOEXCEPT {
3070b57cec5SDimitry Andric      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
3080b57cec5SDimitry Andric      _LIBCPP_UNREACHABLE();
3090b57cec5SDimitry Andric    }
3100b57cec5SDimitry Andric
3110b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
3120b57cec5SDimitry Andric    const_reference operator[](size_type) const _NOEXCEPT {
3130b57cec5SDimitry Andric      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
3140b57cec5SDimitry Andric      _LIBCPP_UNREACHABLE();
3150b57cec5SDimitry Andric    }
3160b57cec5SDimitry Andric
3170b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3180b57cec5SDimitry Andric    reference at(size_type) {
3190b57cec5SDimitry Andric      __throw_out_of_range("array<T, 0>::at");
3200b57cec5SDimitry Andric      _LIBCPP_UNREACHABLE();
3210b57cec5SDimitry Andric    }
3220b57cec5SDimitry Andric
3230b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3240b57cec5SDimitry Andric    const_reference at(size_type) const {
3250b57cec5SDimitry Andric      __throw_out_of_range("array<T, 0>::at");
3260b57cec5SDimitry Andric      _LIBCPP_UNREACHABLE();
3270b57cec5SDimitry Andric    }
3280b57cec5SDimitry Andric
3290b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3300b57cec5SDimitry Andric    reference front() _NOEXCEPT {
3310b57cec5SDimitry Andric      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
3320b57cec5SDimitry Andric      _LIBCPP_UNREACHABLE();
3330b57cec5SDimitry Andric    }
3340b57cec5SDimitry Andric
3350b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3360b57cec5SDimitry Andric    const_reference front() const _NOEXCEPT {
3370b57cec5SDimitry Andric      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
3380b57cec5SDimitry Andric      _LIBCPP_UNREACHABLE();
3390b57cec5SDimitry Andric    }
3400b57cec5SDimitry Andric
3410b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3420b57cec5SDimitry Andric    reference back() _NOEXCEPT {
3430b57cec5SDimitry Andric      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
3440b57cec5SDimitry Andric      _LIBCPP_UNREACHABLE();
3450b57cec5SDimitry Andric    }
3460b57cec5SDimitry Andric
3470b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3480b57cec5SDimitry Andric    const_reference back() const _NOEXCEPT {
3490b57cec5SDimitry Andric      _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
3500b57cec5SDimitry Andric      _LIBCPP_UNREACHABLE();
3510b57cec5SDimitry Andric    }
3520b57cec5SDimitry Andric
3530b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3540b57cec5SDimitry Andric    value_type* data() _NOEXCEPT {return reinterpret_cast<value_type*>(__elems_);}
3550b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3560b57cec5SDimitry Andric    const value_type* data() const _NOEXCEPT {return reinterpret_cast<const value_type*>(__elems_);}
3570b57cec5SDimitry Andric};
3580b57cec5SDimitry Andric
3590b57cec5SDimitry Andric
3600b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
3610b57cec5SDimitry Andrictemplate<class _Tp, class... _Args,
362*62cfcf62SDimitry Andric         class = _EnableIf<__all<_IsSame<_Tp, _Args>::value...>::value>
3630b57cec5SDimitry Andric         >
3640b57cec5SDimitry Andricarray(_Tp, _Args...)
3650b57cec5SDimitry Andric  -> array<_Tp, 1 + sizeof...(_Args)>;
3660b57cec5SDimitry Andric#endif
3670b57cec5SDimitry Andric
3680b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size>
3690b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
3700b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
3710b57cec5SDimitry Andricoperator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
3720b57cec5SDimitry Andric{
3730b57cec5SDimitry Andric    return _VSTD::equal(__x.begin(), __x.end(), __y.begin());
3740b57cec5SDimitry Andric}
3750b57cec5SDimitry Andric
3760b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size>
3770b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
3780b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
3790b57cec5SDimitry Andricoperator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
3800b57cec5SDimitry Andric{
3810b57cec5SDimitry Andric    return !(__x == __y);
3820b57cec5SDimitry Andric}
3830b57cec5SDimitry Andric
3840b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size>
3850b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
3860b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
3870b57cec5SDimitry Andricoperator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
3880b57cec5SDimitry Andric{
3890b57cec5SDimitry Andric    return _VSTD::lexicographical_compare(__x.begin(), __x.end(),
3900b57cec5SDimitry Andric                                          __y.begin(), __y.end());
3910b57cec5SDimitry Andric}
3920b57cec5SDimitry Andric
3930b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size>
3940b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
3950b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
3960b57cec5SDimitry Andricoperator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
3970b57cec5SDimitry Andric{
3980b57cec5SDimitry Andric    return __y < __x;
3990b57cec5SDimitry Andric}
4000b57cec5SDimitry Andric
4010b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size>
4020b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
4030b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
4040b57cec5SDimitry Andricoperator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
4050b57cec5SDimitry Andric{
4060b57cec5SDimitry Andric    return !(__y < __x);
4070b57cec5SDimitry Andric}
4080b57cec5SDimitry Andric
4090b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size>
4100b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
4110b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
4120b57cec5SDimitry Andricoperator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
4130b57cec5SDimitry Andric{
4140b57cec5SDimitry Andric    return !(__x < __y);
4150b57cec5SDimitry Andric}
4160b57cec5SDimitry Andric
4170b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size>
4180b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
4190b57cec5SDimitry Andrictypename enable_if
4200b57cec5SDimitry Andric<
4210b57cec5SDimitry Andric    _Size == 0 ||
4220b57cec5SDimitry Andric    __is_swappable<_Tp>::value,
4230b57cec5SDimitry Andric    void
4240b57cec5SDimitry Andric>::type
4250b57cec5SDimitry Andricswap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y)
4260b57cec5SDimitry Andric                                  _NOEXCEPT_(noexcept(__x.swap(__y)))
4270b57cec5SDimitry Andric{
4280b57cec5SDimitry Andric    __x.swap(__y);
4290b57cec5SDimitry Andric}
4300b57cec5SDimitry Andric
4310b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size>
4320b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> >
4330b57cec5SDimitry Andric    : public integral_constant<size_t, _Size> {};
4340b57cec5SDimitry Andric
4350b57cec5SDimitry Andrictemplate <size_t _Ip, class _Tp, size_t _Size>
4360b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> >
4370b57cec5SDimitry Andric{
4380b57cec5SDimitry Andric    static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)");
4390b57cec5SDimitry Andric    typedef _Tp type;
4400b57cec5SDimitry Andric};
4410b57cec5SDimitry Andric
4420b57cec5SDimitry Andrictemplate <size_t _Ip, class _Tp, size_t _Size>
4430b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
4440b57cec5SDimitry Andric_Tp&
4450b57cec5SDimitry Andricget(array<_Tp, _Size>& __a) _NOEXCEPT
4460b57cec5SDimitry Andric{
4470b57cec5SDimitry Andric    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)");
4480b57cec5SDimitry Andric    return __a.__elems_[_Ip];
4490b57cec5SDimitry Andric}
4500b57cec5SDimitry Andric
4510b57cec5SDimitry Andrictemplate <size_t _Ip, class _Tp, size_t _Size>
4520b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
4530b57cec5SDimitry Andricconst _Tp&
4540b57cec5SDimitry Andricget(const array<_Tp, _Size>& __a) _NOEXCEPT
4550b57cec5SDimitry Andric{
4560b57cec5SDimitry Andric    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)");
4570b57cec5SDimitry Andric    return __a.__elems_[_Ip];
4580b57cec5SDimitry Andric}
4590b57cec5SDimitry Andric
4600b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
4610b57cec5SDimitry Andric
4620b57cec5SDimitry Andrictemplate <size_t _Ip, class _Tp, size_t _Size>
4630b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
4640b57cec5SDimitry Andric_Tp&&
4650b57cec5SDimitry Andricget(array<_Tp, _Size>&& __a) _NOEXCEPT
4660b57cec5SDimitry Andric{
4670b57cec5SDimitry Andric    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)");
4680b57cec5SDimitry Andric    return _VSTD::move(__a.__elems_[_Ip]);
4690b57cec5SDimitry Andric}
4700b57cec5SDimitry Andric
4710b57cec5SDimitry Andrictemplate <size_t _Ip, class _Tp, size_t _Size>
4720b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
4730b57cec5SDimitry Andricconst _Tp&&
4740b57cec5SDimitry Andricget(const array<_Tp, _Size>&& __a) _NOEXCEPT
4750b57cec5SDimitry Andric{
4760b57cec5SDimitry Andric    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)");
4770b57cec5SDimitry Andric    return _VSTD::move(__a.__elems_[_Ip]);
4780b57cec5SDimitry Andric}
4790b57cec5SDimitry Andric
4800b57cec5SDimitry Andric#endif  // !_LIBCPP_CXX03_LANG
4810b57cec5SDimitry Andric
4820b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
4830b57cec5SDimitry Andric
4840b57cec5SDimitry Andric#endif  // _LIBCPP_ARRAY
485