xref: /freebsd/contrib/llvm-project/libcxx/include/array (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
10b57cec5SDimitry Andric// -*- C++ -*-
2349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
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
355ffd83dbSDimitry Andric    void fill(const T& u);                                      // constexpr in C++20
365ffd83dbSDimitry Andric    void swap(array& a) noexcept(is_nothrow_swappable_v<T>);    // constexpr in C++20
370b57cec5SDimitry Andric
380b57cec5SDimitry Andric    // iterators:
395ffd83dbSDimitry Andric    iterator begin() noexcept;                                  // constexpr in C++17
405ffd83dbSDimitry Andric    const_iterator begin() const noexcept;                      // constexpr in C++17
415ffd83dbSDimitry Andric    iterator end() noexcept;                                    // constexpr in C++17
425ffd83dbSDimitry Andric    const_iterator end() const noexcept;                        // constexpr in C++17
430b57cec5SDimitry Andric
445ffd83dbSDimitry Andric    reverse_iterator rbegin() noexcept;                         // constexpr in C++17
455ffd83dbSDimitry Andric    const_reverse_iterator rbegin() const noexcept;             // constexpr in C++17
465ffd83dbSDimitry Andric    reverse_iterator rend() noexcept;                           // constexpr in C++17
475ffd83dbSDimitry Andric    const_reverse_iterator rend() const noexcept;               // constexpr in C++17
480b57cec5SDimitry Andric
495ffd83dbSDimitry Andric    const_iterator cbegin() const noexcept;                     // constexpr in C++17
505ffd83dbSDimitry Andric    const_iterator cend() const noexcept;                       // constexpr in C++17
515ffd83dbSDimitry Andric    const_reverse_iterator crbegin() const noexcept;            // constexpr in C++17
525ffd83dbSDimitry Andric    const_reverse_iterator crend() const noexcept;              // constexpr in C++17
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:
605ffd83dbSDimitry Andric    reference operator[](size_type n);                          // constexpr in C++17
610b57cec5SDimitry Andric    const_reference operator[](size_type n) const;              // constexpr in C++14
625ffd83dbSDimitry Andric    reference at(size_type n);                                  // constexpr in C++17
630b57cec5SDimitry Andric    const_reference at(size_type n) const;                      // constexpr in C++14
640b57cec5SDimitry Andric
655ffd83dbSDimitry Andric    reference front();                                          // constexpr in C++17
660b57cec5SDimitry Andric    const_reference front() const;                              // constexpr in C++14
675ffd83dbSDimitry Andric    reference back();                                           // constexpr in C++17
680b57cec5SDimitry Andric    const_reference back() const;                               // constexpr in C++14
690b57cec5SDimitry Andric
705ffd83dbSDimitry Andric    T* data() noexcept;                                         // constexpr in C++17
715ffd83dbSDimitry Andric    const T* data() const noexcept;                             // constexpr in C++17
720b57cec5SDimitry Andric};
730b57cec5SDimitry Andric
740b57cec5SDimitry Andrictemplate <class T, class... U>
755ffd83dbSDimitry Andric  array(T, U...) -> array<T, 1 + sizeof...(U)>;                 // C++17
760b57cec5SDimitry Andric
770b57cec5SDimitry Andrictemplate <class T, size_t N>
785ffd83dbSDimitry Andric  bool operator==(const array<T,N>& x, const array<T,N>& y);    // constexpr in C++20
790b57cec5SDimitry Andrictemplate <class T, size_t N>
8006c3fb27SDimitry Andric  bool operator!=(const array<T,N>& x, const array<T,N>& y);    // removed in C++20
810b57cec5SDimitry Andrictemplate <class T, size_t N>
8206c3fb27SDimitry Andric  bool operator<(const array<T,N>& x, const array<T,N>& y);     // removed in C++20
830b57cec5SDimitry Andrictemplate <class T, size_t N>
8406c3fb27SDimitry Andric  bool operator>(const array<T,N>& x, const array<T,N>& y);     // removed in C++20
850b57cec5SDimitry Andrictemplate <class T, size_t N>
8606c3fb27SDimitry Andric  bool operator<=(const array<T,N>& x, const array<T,N>& y);    // removed in C++20
870b57cec5SDimitry Andrictemplate <class T, size_t N>
8806c3fb27SDimitry Andric  bool operator>=(const array<T,N>& x, const array<T,N>& y);    // removed in C++20
8906c3fb27SDimitry Andrictemplate<class T, size_t N>
9006c3fb27SDimitry Andric  constexpr synth-three-way-result<T>
9106c3fb27SDimitry Andric    operator<=>(const array<T, N>& x, const array<T, N>& y);    // since C++20
920b57cec5SDimitry Andric
930b57cec5SDimitry Andrictemplate <class T, size_t N >
945ffd83dbSDimitry Andric  void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y))); // constexpr in C++20
955ffd83dbSDimitry Andric
965ffd83dbSDimitry Andrictemplate <class T, size_t N>
975ffd83dbSDimitry Andric  constexpr array<remove_cv_t<T>, N> to_array(T (&a)[N]);  // C++20
985ffd83dbSDimitry Andrictemplate <class T, size_t N>
995ffd83dbSDimitry Andric  constexpr array<remove_cv_t<T>, N> to_array(T (&&a)[N]); // C++20
1000b57cec5SDimitry Andric
1010b57cec5SDimitry Andrictemplate <class T> struct tuple_size;
1020b57cec5SDimitry Andrictemplate <size_t I, class T> struct tuple_element;
1030b57cec5SDimitry Andrictemplate <class T, size_t N> struct tuple_size<array<T, N>>;
1040b57cec5SDimitry Andrictemplate <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>;
1050b57cec5SDimitry Andrictemplate <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept;               // constexpr in C++14
1060b57cec5SDimitry Andrictemplate <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept;   // constexpr in C++14
1070b57cec5SDimitry Andrictemplate <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept;             // constexpr in C++14
1080b57cec5SDimitry Andrictemplate <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14
1090b57cec5SDimitry Andric
1100b57cec5SDimitry Andric}  // std
1110b57cec5SDimitry Andric
1120b57cec5SDimitry Andric*/
1130b57cec5SDimitry Andric
11481ad6265SDimitry Andric#include <__algorithm/equal.h>
11581ad6265SDimitry Andric#include <__algorithm/fill_n.h>
11681ad6265SDimitry Andric#include <__algorithm/lexicographical_compare.h>
11706c3fb27SDimitry Andric#include <__algorithm/lexicographical_compare_three_way.h>
11881ad6265SDimitry Andric#include <__algorithm/swap_ranges.h>
11981ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler
1200b57cec5SDimitry Andric#include <__config>
12106c3fb27SDimitry Andric#include <__fwd/array.h>
12281ad6265SDimitry Andric#include <__iterator/reverse_iterator.h>
12306c3fb27SDimitry Andric#include <__tuple/sfinae_helpers.h>
12406c3fb27SDimitry Andric#include <__type_traits/conditional.h>
12506c3fb27SDimitry Andric#include <__type_traits/is_array.h>
12606c3fb27SDimitry Andric#include <__type_traits/is_const.h>
12706c3fb27SDimitry Andric#include <__type_traits/is_constructible.h>
12806c3fb27SDimitry Andric#include <__type_traits/is_move_constructible.h>
12906c3fb27SDimitry Andric#include <__type_traits/is_nothrow_constructible.h>
13006c3fb27SDimitry Andric#include <__type_traits/is_nothrow_move_constructible.h>
13106c3fb27SDimitry Andric#include <__type_traits/is_same.h>
13206c3fb27SDimitry Andric#include <__type_traits/is_swappable.h>
13306c3fb27SDimitry Andric#include <__type_traits/remove_cv.h>
134*5f757f3fSDimitry Andric#include <__utility/empty.h>
13581ad6265SDimitry Andric#include <__utility/integer_sequence.h>
13681ad6265SDimitry Andric#include <__utility/move.h>
13781ad6265SDimitry Andric#include <__utility/unreachable.h>
138fe6060f1SDimitry Andric#include <stdexcept>
1390b57cec5SDimitry Andric#include <version>
1400b57cec5SDimitry Andric
14181ad6265SDimitry Andric// standard-mandated includes
14281ad6265SDimitry Andric
14381ad6265SDimitry Andric// [iterator.range]
14481ad6265SDimitry Andric#include <__iterator/access.h>
14581ad6265SDimitry Andric#include <__iterator/data.h>
14681ad6265SDimitry Andric#include <__iterator/empty.h>
14781ad6265SDimitry Andric#include <__iterator/reverse_access.h>
14881ad6265SDimitry Andric#include <__iterator/size.h>
14981ad6265SDimitry Andric
15081ad6265SDimitry Andric// [array.syn]
15181ad6265SDimitry Andric#include <compare>
15281ad6265SDimitry Andric#include <initializer_list>
15381ad6265SDimitry Andric
154bdd1243dSDimitry Andric// [tuple.helper]
15506c3fb27SDimitry Andric#include <__tuple/tuple_element.h>
15606c3fb27SDimitry Andric#include <__tuple/tuple_size.h>
157bdd1243dSDimitry Andric
1580b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1590b57cec5SDimitry Andric#  pragma GCC system_header
1600b57cec5SDimitry Andric#endif
1610b57cec5SDimitry Andric
1620b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
1630b57cec5SDimitry Andric
1640b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size>
1650b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS array
1660b57cec5SDimitry Andric{
1670b57cec5SDimitry Andric    // types:
168*5f757f3fSDimitry Andric    using __self                 = array;
169*5f757f3fSDimitry Andric    using value_type             = _Tp;
170*5f757f3fSDimitry Andric    using reference              = value_type&;
171*5f757f3fSDimitry Andric    using const_reference        = const value_type&;
172*5f757f3fSDimitry Andric    using iterator               = value_type*;
173*5f757f3fSDimitry Andric    using const_iterator         = const value_type*;
174*5f757f3fSDimitry Andric    using pointer                = value_type*;
175*5f757f3fSDimitry Andric    using const_pointer          = const value_type*;
176*5f757f3fSDimitry Andric    using size_type              = size_t;
177*5f757f3fSDimitry Andric    using difference_type        = ptrdiff_t;
178*5f757f3fSDimitry Andric    using reverse_iterator       = std::reverse_iterator<iterator>;
179*5f757f3fSDimitry Andric    using const_reverse_iterator = std::reverse_iterator<const_iterator>;
1800b57cec5SDimitry Andric
1810b57cec5SDimitry Andric    _Tp __elems_[_Size];
1820b57cec5SDimitry Andric
1830b57cec5SDimitry Andric    // No explicit construct/copy/destroy for aggregate type
184*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
1855ffd83dbSDimitry Andric    void fill(const value_type& __u) {
186*5f757f3fSDimitry Andric        std::fill_n(data(), _Size, __u);
1870b57cec5SDimitry Andric    }
1880b57cec5SDimitry Andric
189*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
1900b57cec5SDimitry Andric    void swap(array& __a) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) {
191*5f757f3fSDimitry Andric        std::swap_ranges(data(), data() + _Size, __a.data());
1920b57cec5SDimitry Andric    }
1930b57cec5SDimitry Andric
1940b57cec5SDimitry Andric    // iterators:
195*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
1960b57cec5SDimitry Andric    iterator begin() _NOEXCEPT {return iterator(data());}
197*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
1980b57cec5SDimitry Andric    const_iterator begin() const _NOEXCEPT {return const_iterator(data());}
199*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
2000b57cec5SDimitry Andric    iterator end() _NOEXCEPT {return iterator(data() + _Size);}
201*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
2020b57cec5SDimitry Andric    const_iterator end() const _NOEXCEPT {return const_iterator(data() + _Size);}
2030b57cec5SDimitry Andric
204*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
2050b57cec5SDimitry Andric    reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
206*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
2070b57cec5SDimitry Andric    const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
208*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
2090b57cec5SDimitry Andric    reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
210*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
2110b57cec5SDimitry Andric    const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
2120b57cec5SDimitry Andric
213*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
2140b57cec5SDimitry Andric    const_iterator cbegin() const _NOEXCEPT {return begin();}
215*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
2160b57cec5SDimitry Andric    const_iterator cend() const _NOEXCEPT {return end();}
217*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
2180b57cec5SDimitry Andric    const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
219*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
2200b57cec5SDimitry Andric    const_reverse_iterator crend() const _NOEXCEPT {return rend();}
2210b57cec5SDimitry Andric
2220b57cec5SDimitry Andric    // capacity:
223*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
2240b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;}
225*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
2260b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;}
227*5f757f3fSDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI
2285ffd83dbSDimitry Andric    _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return _Size == 0;}
2290b57cec5SDimitry Andric
2300b57cec5SDimitry Andric    // element access:
231*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
2325ffd83dbSDimitry Andric    reference operator[](size_type __n) _NOEXCEPT {
23306c3fb27SDimitry Andric        _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < _Size, "out-of-bounds access in std::array<T, N>");
2345ffd83dbSDimitry Andric        return __elems_[__n];
2355ffd83dbSDimitry Andric    }
236*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
2375ffd83dbSDimitry Andric    const_reference operator[](size_type __n) const _NOEXCEPT {
23806c3fb27SDimitry Andric        _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < _Size, "out-of-bounds access in std::array<T, N>");
2395ffd83dbSDimitry Andric        return __elems_[__n];
2405ffd83dbSDimitry Andric    }
2410b57cec5SDimitry Andric
24206c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference at(size_type __n)
2435ffd83dbSDimitry Andric    {
2445ffd83dbSDimitry Andric        if (__n >= _Size)
2455ffd83dbSDimitry Andric            __throw_out_of_range("array::at");
2465ffd83dbSDimitry Andric        return __elems_[__n];
2475ffd83dbSDimitry Andric    }
2480b57cec5SDimitry Andric
24906c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference at(size_type __n) const
2505ffd83dbSDimitry Andric    {
2515ffd83dbSDimitry Andric        if (__n >= _Size)
2525ffd83dbSDimitry Andric            __throw_out_of_range("array::at");
2535ffd83dbSDimitry Andric        return __elems_[__n];
2545ffd83dbSDimitry Andric    }
2555ffd83dbSDimitry Andric
256*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference front()             _NOEXCEPT {return (*this)[0];}
257*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference front() const _NOEXCEPT {return (*this)[0];}
258*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference back()              _NOEXCEPT {return (*this)[_Size - 1];}
259*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference back() const  _NOEXCEPT {return (*this)[_Size - 1];}
2600b57cec5SDimitry Andric
261*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
2620b57cec5SDimitry Andric    value_type* data() _NOEXCEPT {return __elems_;}
263*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
2640b57cec5SDimitry Andric    const value_type* data() const _NOEXCEPT {return __elems_;}
2650b57cec5SDimitry Andric};
2660b57cec5SDimitry Andric
2670b57cec5SDimitry Andrictemplate <class _Tp>
2680b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS array<_Tp, 0>
2690b57cec5SDimitry Andric{
2700b57cec5SDimitry Andric    // types:
2710b57cec5SDimitry Andric    typedef array __self;
2720b57cec5SDimitry Andric    typedef _Tp                                   value_type;
2730b57cec5SDimitry Andric    typedef value_type&                           reference;
2740b57cec5SDimitry Andric    typedef const value_type&                     const_reference;
2750b57cec5SDimitry Andric    typedef value_type*                           iterator;
2760b57cec5SDimitry Andric    typedef const value_type*                     const_iterator;
2770b57cec5SDimitry Andric    typedef value_type*                           pointer;
2780b57cec5SDimitry Andric    typedef const value_type*                     const_pointer;
2790b57cec5SDimitry Andric    typedef size_t                                size_type;
2800b57cec5SDimitry Andric    typedef ptrdiff_t                             difference_type;
281*5f757f3fSDimitry Andric    typedef std::reverse_iterator<iterator>       reverse_iterator;
282*5f757f3fSDimitry Andric    typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
2830b57cec5SDimitry Andric
284*5f757f3fSDimitry Andric    typedef __conditional_t<is_const<_Tp>::value, const __empty, __empty> _EmptyType;
2850b57cec5SDimitry Andric
2860b57cec5SDimitry Andric    struct  _ArrayInStructT { _Tp __data_[1]; };
287*5f757f3fSDimitry Andric    _ALIGNAS_TYPE(_ArrayInStructT) _EmptyType __elems_[sizeof(_ArrayInStructT)];
2880b57cec5SDimitry Andric
289*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
2905ffd83dbSDimitry Andric    value_type* data() _NOEXCEPT {return nullptr;}
291*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
2925ffd83dbSDimitry Andric    const value_type* data() const _NOEXCEPT {return nullptr;}
2935ffd83dbSDimitry Andric
2940b57cec5SDimitry Andric    // No explicit construct/copy/destroy for aggregate type
295*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
2965ffd83dbSDimitry Andric    void fill(const value_type&) {
2970b57cec5SDimitry Andric      static_assert(!is_const<_Tp>::value,
2980b57cec5SDimitry Andric                    "cannot fill zero-sized array of type 'const T'");
2990b57cec5SDimitry Andric    }
3000b57cec5SDimitry Andric
301*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
3020b57cec5SDimitry Andric    void swap(array&) _NOEXCEPT {
3030b57cec5SDimitry Andric      static_assert(!is_const<_Tp>::value,
3040b57cec5SDimitry Andric                    "cannot swap zero-sized array of type 'const T'");
3050b57cec5SDimitry Andric    }
3060b57cec5SDimitry Andric
3070b57cec5SDimitry Andric    // iterators:
308*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
3090b57cec5SDimitry Andric    iterator begin() _NOEXCEPT {return iterator(data());}
310*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
3110b57cec5SDimitry Andric    const_iterator begin() const _NOEXCEPT {return const_iterator(data());}
312*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
3130b57cec5SDimitry Andric    iterator end() _NOEXCEPT {return iterator(data());}
314*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
3150b57cec5SDimitry Andric    const_iterator end() const _NOEXCEPT {return const_iterator(data());}
3160b57cec5SDimitry Andric
317*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
3180b57cec5SDimitry Andric    reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
319*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
3200b57cec5SDimitry Andric    const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
321*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
3220b57cec5SDimitry Andric    reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
323*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
3240b57cec5SDimitry Andric    const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
3250b57cec5SDimitry Andric
326*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
3270b57cec5SDimitry Andric    const_iterator cbegin() const _NOEXCEPT {return begin();}
328*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
3290b57cec5SDimitry Andric    const_iterator cend() const _NOEXCEPT {return end();}
330*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
3310b57cec5SDimitry Andric    const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
332*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
3330b57cec5SDimitry Andric    const_reverse_iterator crend() const _NOEXCEPT {return rend();}
3340b57cec5SDimitry Andric
3350b57cec5SDimitry Andric    // capacity:
336*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
3370b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return 0; }
338*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
3390b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return 0;}
340*5f757f3fSDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI
3410b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return true;}
3420b57cec5SDimitry Andric
3430b57cec5SDimitry Andric    // element access:
344*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
3450b57cec5SDimitry Andric    reference operator[](size_type) _NOEXCEPT {
34606c3fb27SDimitry Andric      _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
34781ad6265SDimitry Andric      __libcpp_unreachable();
3480b57cec5SDimitry Andric    }
3490b57cec5SDimitry Andric
350*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
3510b57cec5SDimitry Andric    const_reference operator[](size_type) const _NOEXCEPT {
35206c3fb27SDimitry Andric      _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
35381ad6265SDimitry Andric      __libcpp_unreachable();
3540b57cec5SDimitry Andric    }
3550b57cec5SDimitry Andric
356*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
3570b57cec5SDimitry Andric    reference at(size_type) {
3580b57cec5SDimitry Andric      __throw_out_of_range("array<T, 0>::at");
35981ad6265SDimitry Andric      __libcpp_unreachable();
3600b57cec5SDimitry Andric    }
3610b57cec5SDimitry Andric
362*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
3630b57cec5SDimitry Andric    const_reference at(size_type) const {
3640b57cec5SDimitry Andric      __throw_out_of_range("array<T, 0>::at");
36581ad6265SDimitry Andric      __libcpp_unreachable();
3660b57cec5SDimitry Andric    }
3670b57cec5SDimitry Andric
368*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
3690b57cec5SDimitry Andric    reference front() _NOEXCEPT {
37006c3fb27SDimitry Andric      _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::front() on a zero-sized array");
37181ad6265SDimitry Andric      __libcpp_unreachable();
3720b57cec5SDimitry Andric    }
3730b57cec5SDimitry Andric
374*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
3750b57cec5SDimitry Andric    const_reference front() const _NOEXCEPT {
37606c3fb27SDimitry Andric      _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::front() on a zero-sized array");
37781ad6265SDimitry Andric      __libcpp_unreachable();
3780b57cec5SDimitry Andric    }
3790b57cec5SDimitry Andric
380*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
3810b57cec5SDimitry Andric    reference back() _NOEXCEPT {
38206c3fb27SDimitry Andric      _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::back() on a zero-sized array");
38381ad6265SDimitry Andric      __libcpp_unreachable();
3840b57cec5SDimitry Andric    }
3850b57cec5SDimitry Andric
386*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
3870b57cec5SDimitry Andric    const_reference back() const _NOEXCEPT {
38806c3fb27SDimitry Andric      _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::back() on a zero-sized array");
38981ad6265SDimitry Andric      __libcpp_unreachable();
3900b57cec5SDimitry Andric    }
3910b57cec5SDimitry Andric};
3920b57cec5SDimitry Andric
3930b57cec5SDimitry Andric
39406c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
3950b57cec5SDimitry Andrictemplate<class _Tp, class... _Args,
396349cc55cSDimitry Andric         class = enable_if_t<__all<_IsSame<_Tp, _Args>::value...>::value>
3970b57cec5SDimitry Andric         >
3980b57cec5SDimitry Andricarray(_Tp, _Args...)
3990b57cec5SDimitry Andric  -> array<_Tp, 1 + sizeof...(_Args)>;
4000b57cec5SDimitry Andric#endif
4010b57cec5SDimitry Andric
4020b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size>
403*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
404bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 bool
4050b57cec5SDimitry Andricoperator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
4060b57cec5SDimitry Andric{
407*5f757f3fSDimitry Andric    return std::equal(__x.begin(), __x.end(), __y.begin());
4080b57cec5SDimitry Andric}
4090b57cec5SDimitry Andric
41006c3fb27SDimitry Andric#if _LIBCPP_STD_VER <= 17
41106c3fb27SDimitry Andric
4120b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size>
41306c3fb27SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
4140b57cec5SDimitry Andric    return !(__x == __y);
4150b57cec5SDimitry Andric}
4160b57cec5SDimitry Andric
4170b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size>
41806c3fb27SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
419*5f757f3fSDimitry Andric    return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
4200b57cec5SDimitry Andric}
4210b57cec5SDimitry Andric
4220b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size>
42306c3fb27SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
4240b57cec5SDimitry Andric    return __y < __x;
4250b57cec5SDimitry Andric}
4260b57cec5SDimitry Andric
4270b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size>
42806c3fb27SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
4290b57cec5SDimitry Andric    return !(__y < __x);
4300b57cec5SDimitry Andric}
4310b57cec5SDimitry Andric
4320b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size>
43306c3fb27SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
4340b57cec5SDimitry Andric    return !(__x < __y);
4350b57cec5SDimitry Andric}
4360b57cec5SDimitry Andric
43706c3fb27SDimitry Andric#else // _LIBCPP_STD_VER <= 17
43806c3fb27SDimitry Andric
43906c3fb27SDimitry Andrictemplate <class _Tp, size_t _Size>
44006c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr __synth_three_way_result<_Tp>
44106c3fb27SDimitry Andricoperator<=>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
44206c3fb27SDimitry Andric    return std::lexicographical_compare_three_way(
44306c3fb27SDimitry Andric        __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way<_Tp, _Tp>);
44406c3fb27SDimitry Andric}
44506c3fb27SDimitry Andric
44606c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER <= 17
44706c3fb27SDimitry Andric
448*5f757f3fSDimitry Andrictemplate <class _Tp, size_t _Size, __enable_if_t<_Size == 0 || __is_swappable<_Tp>::value, int> = 0>
449*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
450*5f757f3fSDimitry Andricvoid
4510b57cec5SDimitry Andricswap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y)
4520b57cec5SDimitry Andric                                  _NOEXCEPT_(noexcept(__x.swap(__y)))
4530b57cec5SDimitry Andric{
4540b57cec5SDimitry Andric    __x.swap(__y);
4550b57cec5SDimitry Andric}
4560b57cec5SDimitry Andric
4570b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size>
4580b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> >
4590b57cec5SDimitry Andric    : public integral_constant<size_t, _Size> {};
4600b57cec5SDimitry Andric
4610b57cec5SDimitry Andrictemplate <size_t _Ip, class _Tp, size_t _Size>
4620b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> >
4630b57cec5SDimitry Andric{
4640b57cec5SDimitry Andric    static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)");
4650b57cec5SDimitry Andric    typedef _Tp type;
4660b57cec5SDimitry Andric};
4670b57cec5SDimitry Andric
4680b57cec5SDimitry Andrictemplate <size_t _Ip, class _Tp, size_t _Size>
469*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
4700b57cec5SDimitry Andric_Tp&
4710b57cec5SDimitry Andricget(array<_Tp, _Size>& __a) _NOEXCEPT
4720b57cec5SDimitry Andric{
4730b57cec5SDimitry Andric    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)");
4740b57cec5SDimitry Andric    return __a.__elems_[_Ip];
4750b57cec5SDimitry Andric}
4760b57cec5SDimitry Andric
4770b57cec5SDimitry Andrictemplate <size_t _Ip, class _Tp, size_t _Size>
478*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
4790b57cec5SDimitry Andricconst _Tp&
4800b57cec5SDimitry Andricget(const array<_Tp, _Size>& __a) _NOEXCEPT
4810b57cec5SDimitry Andric{
4820b57cec5SDimitry Andric    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)");
4830b57cec5SDimitry Andric    return __a.__elems_[_Ip];
4840b57cec5SDimitry Andric}
4850b57cec5SDimitry Andric
4860b57cec5SDimitry Andrictemplate <size_t _Ip, class _Tp, size_t _Size>
487*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
4880b57cec5SDimitry Andric_Tp&&
4890b57cec5SDimitry Andricget(array<_Tp, _Size>&& __a) _NOEXCEPT
4900b57cec5SDimitry Andric{
4910b57cec5SDimitry Andric    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)");
492*5f757f3fSDimitry Andric    return std::move(__a.__elems_[_Ip]);
4930b57cec5SDimitry Andric}
4940b57cec5SDimitry Andric
4950b57cec5SDimitry Andrictemplate <size_t _Ip, class _Tp, size_t _Size>
496*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
4970b57cec5SDimitry Andricconst _Tp&&
4980b57cec5SDimitry Andricget(const array<_Tp, _Size>&& __a) _NOEXCEPT
4990b57cec5SDimitry Andric{
5000b57cec5SDimitry Andric    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)");
501*5f757f3fSDimitry Andric    return std::move(__a.__elems_[_Ip]);
5020b57cec5SDimitry Andric}
5030b57cec5SDimitry Andric
50406c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20
5055ffd83dbSDimitry Andric
5065ffd83dbSDimitry Andrictemplate <typename _Tp, size_t _Size, size_t... _Index>
507*5f757f3fSDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr array<remove_cv_t<_Tp>, _Size>
5085ffd83dbSDimitry Andric__to_array_lvalue_impl(_Tp (&__arr)[_Size], index_sequence<_Index...>) {
5095ffd83dbSDimitry Andric  return {{__arr[_Index]...}};
5105ffd83dbSDimitry Andric}
5115ffd83dbSDimitry Andric
5125ffd83dbSDimitry Andrictemplate <typename _Tp, size_t _Size, size_t... _Index>
513*5f757f3fSDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr array<remove_cv_t<_Tp>, _Size>
5145ffd83dbSDimitry Andric__to_array_rvalue_impl(_Tp(&&__arr)[_Size], index_sequence<_Index...>) {
515*5f757f3fSDimitry Andric  return {{std::move(__arr[_Index])...}};
5165ffd83dbSDimitry Andric}
5175ffd83dbSDimitry Andric
5185ffd83dbSDimitry Andrictemplate <typename _Tp, size_t _Size>
519*5f757f3fSDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr array<remove_cv_t<_Tp>, _Size>
5205ffd83dbSDimitry Andricto_array(_Tp (&__arr)[_Size]) noexcept(is_nothrow_constructible_v<_Tp, _Tp&>) {
5215ffd83dbSDimitry Andric  static_assert(
5225ffd83dbSDimitry Andric      !is_array_v<_Tp>,
5235ffd83dbSDimitry Andric      "[array.creation]/1: to_array does not accept multidimensional arrays.");
5245ffd83dbSDimitry Andric  static_assert(
5255ffd83dbSDimitry Andric      is_constructible_v<_Tp, _Tp&>,
5265ffd83dbSDimitry Andric      "[array.creation]/1: to_array requires copy constructible elements.");
527*5f757f3fSDimitry Andric  return std::__to_array_lvalue_impl(__arr, make_index_sequence<_Size>());
5285ffd83dbSDimitry Andric}
5295ffd83dbSDimitry Andric
5305ffd83dbSDimitry Andrictemplate <typename _Tp, size_t _Size>
531*5f757f3fSDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr array<remove_cv_t<_Tp>, _Size>
5325ffd83dbSDimitry Andricto_array(_Tp(&&__arr)[_Size]) noexcept(is_nothrow_move_constructible_v<_Tp>) {
5335ffd83dbSDimitry Andric  static_assert(
5345ffd83dbSDimitry Andric      !is_array_v<_Tp>,
5355ffd83dbSDimitry Andric      "[array.creation]/4: to_array does not accept multidimensional arrays.");
5365ffd83dbSDimitry Andric  static_assert(
5375ffd83dbSDimitry Andric      is_move_constructible_v<_Tp>,
5385ffd83dbSDimitry Andric      "[array.creation]/4: to_array requires move constructible elements.");
539*5f757f3fSDimitry Andric  return std::__to_array_rvalue_impl(std::move(__arr),
5405ffd83dbSDimitry Andric                                       make_index_sequence<_Size>());
5415ffd83dbSDimitry Andric}
5425ffd83dbSDimitry Andric
54306c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20
5445ffd83dbSDimitry Andric
5450b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
5460b57cec5SDimitry Andric
547bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
548bdd1243dSDimitry Andric#  include <algorithm>
549bdd1243dSDimitry Andric#  include <concepts>
55006c3fb27SDimitry Andric#  include <cstdlib>
551bdd1243dSDimitry Andric#  include <iterator>
55206c3fb27SDimitry Andric#  include <type_traits>
553bdd1243dSDimitry Andric#  include <utility>
554bdd1243dSDimitry Andric#endif
555bdd1243dSDimitry Andric
5560b57cec5SDimitry Andric#endif // _LIBCPP_ARRAY
557