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>
80fe013be4SDimitry Andric  bool operator!=(const array<T,N>& x, const array<T,N>& y);    // removed in C++20
810b57cec5SDimitry Andrictemplate <class T, size_t N>
82fe013be4SDimitry Andric  bool operator<(const array<T,N>& x, const array<T,N>& y);     // removed in C++20
830b57cec5SDimitry Andrictemplate <class T, size_t N>
84fe013be4SDimitry Andric  bool operator>(const array<T,N>& x, const array<T,N>& y);     // removed in C++20
850b57cec5SDimitry Andrictemplate <class T, size_t N>
86fe013be4SDimitry Andric  bool operator<=(const array<T,N>& x, const array<T,N>& y);    // removed in C++20
870b57cec5SDimitry Andrictemplate <class T, size_t N>
88fe013be4SDimitry Andric  bool operator>=(const array<T,N>& x, const array<T,N>& y);    // removed in C++20
89fe013be4SDimitry Andrictemplate<class T, size_t N>
90fe013be4SDimitry Andric  constexpr synth-three-way-result<T>
91fe013be4SDimitry 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>
117fe013be4SDimitry 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>
121fe013be4SDimitry Andric#include <__fwd/array.h>
12281ad6265SDimitry Andric#include <__iterator/reverse_iterator.h>
123fe013be4SDimitry Andric#include <__tuple/sfinae_helpers.h>
124fe013be4SDimitry Andric#include <__type_traits/conditional.h>
125fe013be4SDimitry Andric#include <__type_traits/is_array.h>
126fe013be4SDimitry Andric#include <__type_traits/is_const.h>
127fe013be4SDimitry Andric#include <__type_traits/is_constructible.h>
128fe013be4SDimitry Andric#include <__type_traits/is_move_constructible.h>
129fe013be4SDimitry Andric#include <__type_traits/is_nothrow_constructible.h>
130fe013be4SDimitry Andric#include <__type_traits/is_nothrow_move_constructible.h>
131fe013be4SDimitry Andric#include <__type_traits/is_same.h>
132fe013be4SDimitry Andric#include <__type_traits/is_swappable.h>
133fe013be4SDimitry Andric#include <__type_traits/remove_cv.h>
134c9157d92SDimitry 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]
155fe013be4SDimitry Andric#include <__tuple/tuple_element.h>
156fe013be4SDimitry 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
162*b9d9368bSDimitry Andric_LIBCPP_PUSH_MACROS
163*b9d9368bSDimitry Andric#include <__undef_macros>
164*b9d9368bSDimitry Andric
1650b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
1660b57cec5SDimitry Andric
1670b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size>
168e710425bSDimitry Andricstruct _LIBCPP_TEMPLATE_VIS array {
1690b57cec5SDimitry Andric  // types:
170c9157d92SDimitry Andric  using __self                 = array;
171c9157d92SDimitry Andric  using value_type             = _Tp;
172c9157d92SDimitry Andric  using reference              = value_type&;
173c9157d92SDimitry Andric  using const_reference        = const value_type&;
174c9157d92SDimitry Andric  using iterator               = value_type*;
175c9157d92SDimitry Andric  using const_iterator         = const value_type*;
176c9157d92SDimitry Andric  using pointer                = value_type*;
177c9157d92SDimitry Andric  using const_pointer          = const value_type*;
178c9157d92SDimitry Andric  using size_type              = size_t;
179c9157d92SDimitry Andric  using difference_type        = ptrdiff_t;
180c9157d92SDimitry Andric  using reverse_iterator       = std::reverse_iterator<iterator>;
181c9157d92SDimitry Andric  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
1820b57cec5SDimitry Andric
1830b57cec5SDimitry Andric  _Tp __elems_[_Size];
1840b57cec5SDimitry Andric
1850b57cec5SDimitry Andric  // No explicit construct/copy/destroy for aggregate type
186e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void fill(const value_type& __u) {
187c9157d92SDimitry Andric    std::fill_n(data(), _Size, __u);
1880b57cec5SDimitry Andric  }
1890b57cec5SDimitry Andric
190e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(array& __a)
191e710425bSDimitry Andric      _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) {
192c9157d92SDimitry Andric    std::swap_ranges(data(), data() + _Size, __a.data());
1930b57cec5SDimitry Andric  }
1940b57cec5SDimitry Andric
1950b57cec5SDimitry Andric  // iterators:
196e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator begin() _NOEXCEPT { return iterator(data()); }
197e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator begin() const _NOEXCEPT {
198e710425bSDimitry Andric    return const_iterator(data());
199e710425bSDimitry Andric  }
200e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator end() _NOEXCEPT { return iterator(data() + _Size); }
201e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator end() const _NOEXCEPT {
202e710425bSDimitry Andric    return const_iterator(data() + _Size);
203e710425bSDimitry Andric  }
2040b57cec5SDimitry Andric
205e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rbegin() _NOEXCEPT {
206e710425bSDimitry Andric    return reverse_iterator(end());
207e710425bSDimitry Andric  }
208e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator rbegin() const _NOEXCEPT {
209e710425bSDimitry Andric    return const_reverse_iterator(end());
210e710425bSDimitry Andric  }
211e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rend() _NOEXCEPT {
212e710425bSDimitry Andric    return reverse_iterator(begin());
213e710425bSDimitry Andric  }
214e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator rend() const _NOEXCEPT {
215e710425bSDimitry Andric    return const_reverse_iterator(begin());
216e710425bSDimitry Andric  }
2170b57cec5SDimitry Andric
218e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cbegin() const _NOEXCEPT { return begin(); }
219e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cend() const _NOEXCEPT { return end(); }
220e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator crbegin() const _NOEXCEPT {
221e710425bSDimitry Andric    return rbegin();
222e710425bSDimitry Andric  }
223e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
2240b57cec5SDimitry Andric
2250b57cec5SDimitry Andric  // capacity:
226e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT { return _Size; }
227e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT { return _Size; }
228e710425bSDimitry Andric  _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {
229e710425bSDimitry Andric    return _Size == 0;
230e710425bSDimitry Andric  }
2310b57cec5SDimitry Andric
2320b57cec5SDimitry Andric  // element access:
233e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference operator[](size_type __n) _NOEXCEPT {
234fe013be4SDimitry Andric    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < _Size, "out-of-bounds access in std::array<T, N>");
2355ffd83dbSDimitry Andric    return __elems_[__n];
2365ffd83dbSDimitry Andric  }
237e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference operator[](size_type __n) const _NOEXCEPT {
238fe013be4SDimitry 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
242e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference at(size_type __n) {
2435ffd83dbSDimitry Andric    if (__n >= _Size)
2445ffd83dbSDimitry Andric      __throw_out_of_range("array::at");
2455ffd83dbSDimitry Andric    return __elems_[__n];
2465ffd83dbSDimitry Andric  }
2470b57cec5SDimitry Andric
248e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference at(size_type __n) const {
2495ffd83dbSDimitry Andric    if (__n >= _Size)
2505ffd83dbSDimitry Andric      __throw_out_of_range("array::at");
2515ffd83dbSDimitry Andric    return __elems_[__n];
2525ffd83dbSDimitry Andric  }
2535ffd83dbSDimitry Andric
254c9157d92SDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference front() _NOEXCEPT { return (*this)[0]; }
255c9157d92SDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference front() const _NOEXCEPT { return (*this)[0]; }
256c9157d92SDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference back() _NOEXCEPT { return (*this)[_Size - 1]; }
257e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference back() const _NOEXCEPT {
258e710425bSDimitry Andric    return (*this)[_Size - 1];
259e710425bSDimitry Andric  }
2600b57cec5SDimitry Andric
261e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 value_type* data() _NOEXCEPT { return __elems_; }
262e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const value_type* data() const _NOEXCEPT { return __elems_; }
2630b57cec5SDimitry Andric};
2640b57cec5SDimitry Andric
2650b57cec5SDimitry Andrictemplate <class _Tp>
266e710425bSDimitry Andricstruct _LIBCPP_TEMPLATE_VIS array<_Tp, 0> {
2670b57cec5SDimitry Andric  // types:
2680b57cec5SDimitry Andric  typedef array __self;
2690b57cec5SDimitry Andric  typedef _Tp value_type;
2700b57cec5SDimitry Andric  typedef value_type& reference;
2710b57cec5SDimitry Andric  typedef const value_type& const_reference;
2720b57cec5SDimitry Andric  typedef value_type* iterator;
2730b57cec5SDimitry Andric  typedef const value_type* const_iterator;
2740b57cec5SDimitry Andric  typedef value_type* pointer;
2750b57cec5SDimitry Andric  typedef const value_type* const_pointer;
2760b57cec5SDimitry Andric  typedef size_t size_type;
2770b57cec5SDimitry Andric  typedef ptrdiff_t difference_type;
278c9157d92SDimitry Andric  typedef std::reverse_iterator<iterator> reverse_iterator;
279c9157d92SDimitry Andric  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
2800b57cec5SDimitry Andric
281c9157d92SDimitry Andric  typedef __conditional_t<is_const<_Tp>::value, const __empty, __empty> _EmptyType;
2820b57cec5SDimitry Andric
283e710425bSDimitry Andric  struct _ArrayInStructT {
284e710425bSDimitry Andric    _Tp __data_[1];
285e710425bSDimitry Andric  };
286c9157d92SDimitry Andric  _ALIGNAS_TYPE(_ArrayInStructT) _EmptyType __elems_[sizeof(_ArrayInStructT)];
2870b57cec5SDimitry Andric
288e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 value_type* data() _NOEXCEPT { return nullptr; }
289e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const value_type* data() const _NOEXCEPT { return nullptr; }
2905ffd83dbSDimitry Andric
2910b57cec5SDimitry Andric  // No explicit construct/copy/destroy for aggregate type
292e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void fill(const value_type&) {
293e710425bSDimitry Andric    static_assert(!is_const<_Tp>::value, "cannot fill zero-sized array of type 'const T'");
2940b57cec5SDimitry Andric  }
2950b57cec5SDimitry Andric
296e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(array&) _NOEXCEPT {
297e710425bSDimitry Andric    static_assert(!is_const<_Tp>::value, "cannot swap zero-sized array of type 'const T'");
2980b57cec5SDimitry Andric  }
2990b57cec5SDimitry Andric
3000b57cec5SDimitry Andric  // iterators:
301e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator begin() _NOEXCEPT { return iterator(data()); }
302e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator begin() const _NOEXCEPT {
303e710425bSDimitry Andric    return const_iterator(data());
304e710425bSDimitry Andric  }
305e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator end() _NOEXCEPT { return iterator(data()); }
306e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator end() const _NOEXCEPT {
307e710425bSDimitry Andric    return const_iterator(data());
308e710425bSDimitry Andric  }
3090b57cec5SDimitry Andric
310e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rbegin() _NOEXCEPT {
311e710425bSDimitry Andric    return reverse_iterator(end());
312e710425bSDimitry Andric  }
313e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator rbegin() const _NOEXCEPT {
314e710425bSDimitry Andric    return const_reverse_iterator(end());
315e710425bSDimitry Andric  }
316e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rend() _NOEXCEPT {
317e710425bSDimitry Andric    return reverse_iterator(begin());
318e710425bSDimitry Andric  }
319e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator rend() const _NOEXCEPT {
320e710425bSDimitry Andric    return const_reverse_iterator(begin());
321e710425bSDimitry Andric  }
3220b57cec5SDimitry Andric
323e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cbegin() const _NOEXCEPT { return begin(); }
324e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cend() const _NOEXCEPT { return end(); }
325e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator crbegin() const _NOEXCEPT {
326e710425bSDimitry Andric    return rbegin();
327e710425bSDimitry Andric  }
328e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
3290b57cec5SDimitry Andric
3300b57cec5SDimitry Andric  // capacity:
331e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT { return 0; }
332e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT { return 0; }
333e710425bSDimitry Andric  _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT { return true; }
3340b57cec5SDimitry Andric
3350b57cec5SDimitry Andric  // element access:
336e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference operator[](size_type) _NOEXCEPT {
337fe013be4SDimitry Andric    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
33881ad6265SDimitry Andric    __libcpp_unreachable();
3390b57cec5SDimitry Andric  }
3400b57cec5SDimitry Andric
341e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference operator[](size_type) const _NOEXCEPT {
342fe013be4SDimitry Andric    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
34381ad6265SDimitry Andric    __libcpp_unreachable();
3440b57cec5SDimitry Andric  }
3450b57cec5SDimitry Andric
346e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference at(size_type) {
3470b57cec5SDimitry Andric    __throw_out_of_range("array<T, 0>::at");
34881ad6265SDimitry Andric    __libcpp_unreachable();
3490b57cec5SDimitry Andric  }
3500b57cec5SDimitry Andric
351e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference at(size_type) const {
3520b57cec5SDimitry Andric    __throw_out_of_range("array<T, 0>::at");
35381ad6265SDimitry Andric    __libcpp_unreachable();
3540b57cec5SDimitry Andric  }
3550b57cec5SDimitry Andric
356e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference front() _NOEXCEPT {
357fe013be4SDimitry Andric    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::front() on a zero-sized array");
35881ad6265SDimitry Andric    __libcpp_unreachable();
3590b57cec5SDimitry Andric  }
3600b57cec5SDimitry Andric
361e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference front() const _NOEXCEPT {
362fe013be4SDimitry Andric    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::front() on a zero-sized array");
36381ad6265SDimitry Andric    __libcpp_unreachable();
3640b57cec5SDimitry Andric  }
3650b57cec5SDimitry Andric
366e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference back() _NOEXCEPT {
367fe013be4SDimitry Andric    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::back() on a zero-sized array");
36881ad6265SDimitry Andric    __libcpp_unreachable();
3690b57cec5SDimitry Andric  }
3700b57cec5SDimitry Andric
371e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference back() const _NOEXCEPT {
372fe013be4SDimitry Andric    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::back() on a zero-sized array");
37381ad6265SDimitry Andric    __libcpp_unreachable();
3740b57cec5SDimitry Andric  }
3750b57cec5SDimitry Andric};
3760b57cec5SDimitry Andric
377fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 17
378e710425bSDimitry Andrictemplate <class _Tp, class... _Args, class = enable_if_t<__all<_IsSame<_Tp, _Args>::value...>::value> >
379e710425bSDimitry Andricarray(_Tp, _Args...) -> array<_Tp, 1 + sizeof...(_Args)>;
3800b57cec5SDimitry Andric#endif
3810b57cec5SDimitry Andric
3820b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size>
383e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
384e710425bSDimitry Andricoperator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
385c9157d92SDimitry Andric  return std::equal(__x.begin(), __x.end(), __y.begin());
3860b57cec5SDimitry Andric}
3870b57cec5SDimitry Andric
388fe013be4SDimitry Andric#if _LIBCPP_STD_VER <= 17
389fe013be4SDimitry Andric
3900b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size>
391fe013be4SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
3920b57cec5SDimitry Andric  return !(__x == __y);
3930b57cec5SDimitry Andric}
3940b57cec5SDimitry Andric
3950b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size>
396fe013be4SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
397c9157d92SDimitry Andric  return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
3980b57cec5SDimitry Andric}
3990b57cec5SDimitry Andric
4000b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size>
401fe013be4SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
4020b57cec5SDimitry Andric  return __y < __x;
4030b57cec5SDimitry Andric}
4040b57cec5SDimitry Andric
4050b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size>
406fe013be4SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
4070b57cec5SDimitry Andric  return !(__y < __x);
4080b57cec5SDimitry Andric}
4090b57cec5SDimitry Andric
4100b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size>
411fe013be4SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
4120b57cec5SDimitry Andric  return !(__x < __y);
4130b57cec5SDimitry Andric}
4140b57cec5SDimitry Andric
415fe013be4SDimitry Andric#else // _LIBCPP_STD_VER <= 17
416fe013be4SDimitry Andric
417fe013be4SDimitry Andrictemplate <class _Tp, size_t _Size>
418fe013be4SDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr __synth_three_way_result<_Tp>
419fe013be4SDimitry Andricoperator<=>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
420fe013be4SDimitry Andric  return std::lexicographical_compare_three_way(
421fe013be4SDimitry Andric      __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way<_Tp, _Tp>);
422fe013be4SDimitry Andric}
423fe013be4SDimitry Andric
424fe013be4SDimitry Andric#endif // _LIBCPP_STD_VER <= 17
425fe013be4SDimitry Andric
426c9157d92SDimitry Andrictemplate <class _Tp, size_t _Size, __enable_if_t<_Size == 0 || __is_swappable<_Tp>::value, int> = 0>
427e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y)
428e710425bSDimitry Andric    _NOEXCEPT_(noexcept(__x.swap(__y))) {
4290b57cec5SDimitry Andric  __x.swap(__y);
4300b57cec5SDimitry Andric}
4310b57cec5SDimitry Andric
4320b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size>
433e710425bSDimitry Andricstruct _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> > : public integral_constant<size_t, _Size> {};
4340b57cec5SDimitry Andric
4350b57cec5SDimitry Andrictemplate <size_t _Ip, class _Tp, size_t _Size>
436e710425bSDimitry Andricstruct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> > {
4370b57cec5SDimitry Andric  static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)");
4380b57cec5SDimitry Andric  typedef _Tp type;
4390b57cec5SDimitry Andric};
4400b57cec5SDimitry Andric
4410b57cec5SDimitry Andrictemplate <size_t _Ip, class _Tp, size_t _Size>
442e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp& get(array<_Tp, _Size>& __a) _NOEXCEPT {
4430b57cec5SDimitry Andric  static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)");
4440b57cec5SDimitry Andric  return __a.__elems_[_Ip];
4450b57cec5SDimitry Andric}
4460b57cec5SDimitry Andric
4470b57cec5SDimitry Andrictemplate <size_t _Ip, class _Tp, size_t _Size>
448e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp& get(const array<_Tp, _Size>& __a) _NOEXCEPT {
4490b57cec5SDimitry Andric  static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)");
4500b57cec5SDimitry Andric  return __a.__elems_[_Ip];
4510b57cec5SDimitry Andric}
4520b57cec5SDimitry Andric
4530b57cec5SDimitry Andrictemplate <size_t _Ip, class _Tp, size_t _Size>
454e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp&& get(array<_Tp, _Size>&& __a) _NOEXCEPT {
4550b57cec5SDimitry Andric  static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)");
456c9157d92SDimitry Andric  return std::move(__a.__elems_[_Ip]);
4570b57cec5SDimitry Andric}
4580b57cec5SDimitry Andric
4590b57cec5SDimitry Andrictemplate <size_t _Ip, class _Tp, size_t _Size>
460e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&& get(const array<_Tp, _Size>&& __a) _NOEXCEPT {
4610b57cec5SDimitry Andric  static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)");
462c9157d92SDimitry Andric  return std::move(__a.__elems_[_Ip]);
4630b57cec5SDimitry Andric}
4640b57cec5SDimitry Andric
465fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 20
4665ffd83dbSDimitry Andric
4675ffd83dbSDimitry Andrictemplate <typename _Tp, size_t _Size, size_t... _Index>
468c9157d92SDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr array<remove_cv_t<_Tp>, _Size>
4695ffd83dbSDimitry Andric__to_array_lvalue_impl(_Tp (&__arr)[_Size], index_sequence<_Index...>) {
4705ffd83dbSDimitry Andric  return {{__arr[_Index]...}};
4715ffd83dbSDimitry Andric}
4725ffd83dbSDimitry Andric
4735ffd83dbSDimitry Andrictemplate <typename _Tp, size_t _Size, size_t... _Index>
474c9157d92SDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr array<remove_cv_t<_Tp>, _Size>
4755ffd83dbSDimitry Andric__to_array_rvalue_impl(_Tp (&&__arr)[_Size], index_sequence<_Index...>) {
476c9157d92SDimitry Andric  return {{std::move(__arr[_Index])...}};
4775ffd83dbSDimitry Andric}
4785ffd83dbSDimitry Andric
4795ffd83dbSDimitry Andrictemplate <typename _Tp, size_t _Size>
480c9157d92SDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr array<remove_cv_t<_Tp>, _Size>
4815ffd83dbSDimitry Andricto_array(_Tp (&__arr)[_Size]) noexcept(is_nothrow_constructible_v<_Tp, _Tp&>) {
482e710425bSDimitry Andric  static_assert(!is_array_v<_Tp>, "[array.creation]/1: to_array does not accept multidimensional arrays.");
483e710425bSDimitry Andric  static_assert(is_constructible_v<_Tp, _Tp&>, "[array.creation]/1: to_array requires copy constructible elements.");
484c9157d92SDimitry Andric  return std::__to_array_lvalue_impl(__arr, make_index_sequence<_Size>());
4855ffd83dbSDimitry Andric}
4865ffd83dbSDimitry Andric
4875ffd83dbSDimitry Andrictemplate <typename _Tp, size_t _Size>
488c9157d92SDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr array<remove_cv_t<_Tp>, _Size>
4895ffd83dbSDimitry Andricto_array(_Tp (&&__arr)[_Size]) noexcept(is_nothrow_move_constructible_v<_Tp>) {
490e710425bSDimitry Andric  static_assert(!is_array_v<_Tp>, "[array.creation]/4: to_array does not accept multidimensional arrays.");
491e710425bSDimitry Andric  static_assert(is_move_constructible_v<_Tp>, "[array.creation]/4: to_array requires move constructible elements.");
492e710425bSDimitry Andric  return std::__to_array_rvalue_impl(std::move(__arr), make_index_sequence<_Size>());
4935ffd83dbSDimitry Andric}
4945ffd83dbSDimitry Andric
495fe013be4SDimitry Andric#endif // _LIBCPP_STD_VER >= 20
4965ffd83dbSDimitry Andric
4970b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
4980b57cec5SDimitry Andric
499*b9d9368bSDimitry Andric_LIBCPP_POP_MACROS
500*b9d9368bSDimitry Andric
501bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
502bdd1243dSDimitry Andric#  include <algorithm>
503bdd1243dSDimitry Andric#  include <concepts>
504fe013be4SDimitry Andric#  include <cstdlib>
505bdd1243dSDimitry Andric#  include <iterator>
506fe013be4SDimitry Andric#  include <type_traits>
507bdd1243dSDimitry Andric#  include <utility>
508bdd1243dSDimitry Andric#endif
509bdd1243dSDimitry Andric
5100b57cec5SDimitry Andric#endif // _LIBCPP_ARRAY
511