• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_ARRAY
11#define _LIBCPP_ARRAY
12
13/*
14    array synopsis
15
16namespace std
17{
18template <class T, size_t N >
19struct array
20{
21    // types:
22    using value_type             = T;
23    using pointer                = T*;
24    using const_pointer          = const T*;
25    using reference              = T&;
26    using const_reference        = const T&;
27    using size_type              = size_t;
28    using difference_type        = ptrdiff_t;
29    using iterator               = implementation-defined;
30    using const_iterator         = implementation-defined;
31    using reverse_iterator       = std::reverse_iterator<iterator>;
32    using const_reverse_iterator = std::reverse_iterator<const_iterator>;
33
34    // No explicit construct/copy/destroy for aggregate type
35    void fill(const T& u);                                      // constexpr in C++20
36    void swap(array& a) noexcept(is_nothrow_swappable_v<T>);    // constexpr in C++20
37
38    // iterators:
39    iterator begin() noexcept;                                  // constexpr in C++17
40    const_iterator begin() const noexcept;                      // constexpr in C++17
41    iterator end() noexcept;                                    // constexpr in C++17
42    const_iterator end() const noexcept;                        // constexpr in C++17
43
44    reverse_iterator rbegin() noexcept;                         // constexpr in C++17
45    const_reverse_iterator rbegin() const noexcept;             // constexpr in C++17
46    reverse_iterator rend() noexcept;                           // constexpr in C++17
47    const_reverse_iterator rend() const noexcept;               // constexpr in C++17
48
49    const_iterator cbegin() const noexcept;                     // constexpr in C++17
50    const_iterator cend() const noexcept;                       // constexpr in C++17
51    const_reverse_iterator crbegin() const noexcept;            // constexpr in C++17
52    const_reverse_iterator crend() const noexcept;              // constexpr in C++17
53
54    // capacity:
55    constexpr size_type size() const noexcept;
56    constexpr size_type max_size() const noexcept;
57    constexpr bool empty() const noexcept;
58
59    // element access:
60    reference operator[](size_type n);                          // constexpr in C++17
61    const_reference operator[](size_type n) const;              // constexpr in C++14
62    reference at(size_type n);                                  // constexpr in C++17
63    const_reference at(size_type n) const;                      // constexpr in C++14
64
65    reference front();                                          // constexpr in C++17
66    const_reference front() const;                              // constexpr in C++14
67    reference back();                                           // constexpr in C++17
68    const_reference back() const;                               // constexpr in C++14
69
70    T* data() noexcept;                                         // constexpr in C++17
71    const T* data() const noexcept;                             // constexpr in C++17
72};
73
74template <class T, class... U>
75  array(T, U...) -> array<T, 1 + sizeof...(U)>;                 // C++17
76
77template <class T, size_t N>
78  bool operator==(const array<T,N>& x, const array<T,N>& y);    // constexpr in C++20
79template <class T, size_t N>
80  bool operator!=(const array<T,N>& x, const array<T,N>& y);    // removed in C++20
81template <class T, size_t N>
82  bool operator<(const array<T,N>& x, const array<T,N>& y);     // removed in C++20
83template <class T, size_t N>
84  bool operator>(const array<T,N>& x, const array<T,N>& y);     // removed in C++20
85template <class T, size_t N>
86  bool operator<=(const array<T,N>& x, const array<T,N>& y);    // removed in C++20
87template <class T, size_t N>
88  bool operator>=(const array<T,N>& x, const array<T,N>& y);    // removed in C++20
89template<class T, size_t N>
90  constexpr synth-three-way-result<T>
91    operator<=>(const array<T, N>& x, const array<T, N>& y);    // since C++20
92
93template <class T, size_t N >
94  void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y))); // constexpr in C++20
95
96template <class T, size_t N>
97  constexpr array<remove_cv_t<T>, N> to_array(T (&a)[N]);  // C++20
98template <class T, size_t N>
99  constexpr array<remove_cv_t<T>, N> to_array(T (&&a)[N]); // C++20
100
101template <class T> struct tuple_size;
102template <size_t I, class T> struct tuple_element;
103template <class T, size_t N> struct tuple_size<array<T, N>>;
104template <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>;
105template <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept;               // constexpr in C++14
106template <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept;   // constexpr in C++14
107template <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept;             // constexpr in C++14
108template <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14
109
110}  // std
111
112*/
113
114#include <__algorithm/equal.h>
115#include <__algorithm/fill_n.h>
116#include <__algorithm/lexicographical_compare.h>
117#include <__algorithm/lexicographical_compare_three_way.h>
118#include <__algorithm/swap_ranges.h>
119#include <__assert>
120#include <__config>
121#include <__cstddef/ptrdiff_t.h>
122#include <__fwd/array.h>
123#include <__iterator/reverse_iterator.h>
124#include <__iterator/static_bounded_iter.h>
125#include <__iterator/wrap_iter.h>
126#include <__tuple/sfinae_helpers.h>
127#include <__type_traits/conditional.h>
128#include <__type_traits/conjunction.h>
129#include <__type_traits/enable_if.h>
130#include <__type_traits/is_array.h>
131#include <__type_traits/is_const.h>
132#include <__type_traits/is_constructible.h>
133#include <__type_traits/is_nothrow_constructible.h>
134#include <__type_traits/is_same.h>
135#include <__type_traits/is_swappable.h>
136#include <__type_traits/is_trivially_relocatable.h>
137#include <__type_traits/remove_cv.h>
138#include <__utility/empty.h>
139#include <__utility/integer_sequence.h>
140#include <__utility/move.h>
141#include <__utility/unreachable.h>
142#include <stdexcept>
143#include <version>
144
145// standard-mandated includes
146
147// [iterator.range]
148#include <__iterator/access.h>
149#include <__iterator/data.h>
150#include <__iterator/empty.h>
151#include <__iterator/reverse_access.h>
152#include <__iterator/size.h>
153
154// [array.syn]
155#include <compare>
156#include <initializer_list>
157
158// [tuple.helper]
159#include <__tuple/tuple_element.h>
160#include <__tuple/tuple_size.h>
161
162#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
163#  pragma GCC system_header
164#endif
165
166_LIBCPP_PUSH_MACROS
167#include <__undef_macros>
168
169_LIBCPP_BEGIN_NAMESPACE_STD
170
171template <class _Tp, size_t _Size>
172struct _LIBCPP_TEMPLATE_VIS array {
173  using __trivially_relocatable = __conditional_t<__libcpp_is_trivially_relocatable<_Tp>::value, array, void>;
174
175  // types:
176  using __self          = array;
177  using value_type      = _Tp;
178  using reference       = value_type&;
179  using const_reference = const value_type&;
180  using pointer         = value_type*;
181  using const_pointer   = const value_type*;
182#if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
183  using iterator       = __static_bounded_iter<pointer, _Size>;
184  using const_iterator = __static_bounded_iter<const_pointer, _Size>;
185#elif defined(_LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY)
186  using iterator       = __wrap_iter<pointer>;
187  using const_iterator = __wrap_iter<const_pointer>;
188#else
189  using iterator       = pointer;
190  using const_iterator = const_pointer;
191#endif
192  using size_type              = size_t;
193  using difference_type        = ptrdiff_t;
194  using reverse_iterator       = std::reverse_iterator<iterator>;
195  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
196
197  _Tp __elems_[_Size];
198
199  // No explicit construct/copy/destroy for aggregate type
200  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void fill(const value_type& __u) {
201    std::fill_n(data(), _Size, __u);
202  }
203
204  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(array& __a) _NOEXCEPT_(__is_nothrow_swappable_v<_Tp>) {
205    std::swap_ranges(data(), data() + _Size, __a.data());
206  }
207
208  // iterators:
209  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator begin() _NOEXCEPT {
210#if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
211    return std::__make_static_bounded_iter<_Size>(data(), data());
212#else
213    return iterator(data());
214#endif
215  }
216  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator begin() const _NOEXCEPT {
217#if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
218    return std::__make_static_bounded_iter<_Size>(data(), data());
219#else
220    return const_iterator(data());
221#endif
222  }
223  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator end() _NOEXCEPT {
224#if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
225    return std::__make_static_bounded_iter<_Size>(data() + _Size, data());
226#else
227    return iterator(data() + _Size);
228#endif
229  }
230  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator end() const _NOEXCEPT {
231#if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
232    return std::__make_static_bounded_iter<_Size>(data() + _Size, data());
233#else
234    return const_iterator(data() + _Size);
235#endif
236  }
237
238  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rbegin() _NOEXCEPT {
239    return reverse_iterator(end());
240  }
241  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator rbegin() const _NOEXCEPT {
242    return const_reverse_iterator(end());
243  }
244  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rend() _NOEXCEPT {
245    return reverse_iterator(begin());
246  }
247  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator rend() const _NOEXCEPT {
248    return const_reverse_iterator(begin());
249  }
250
251  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cbegin() const _NOEXCEPT { return begin(); }
252  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cend() const _NOEXCEPT { return end(); }
253  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator crbegin() const _NOEXCEPT {
254    return rbegin();
255  }
256  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
257
258  // capacity:
259  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT { return _Size; }
260  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT { return _Size; }
261  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT { return _Size == 0; }
262
263  // element access:
264  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference operator[](size_type __n) _NOEXCEPT {
265    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < _Size, "out-of-bounds access in std::array<T, N>");
266    return __elems_[__n];
267  }
268  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference operator[](size_type __n) const _NOEXCEPT {
269    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < _Size, "out-of-bounds access in std::array<T, N>");
270    return __elems_[__n];
271  }
272
273  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference at(size_type __n) {
274    if (__n >= _Size)
275      __throw_out_of_range("array::at");
276    return __elems_[__n];
277  }
278
279  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference at(size_type __n) const {
280    if (__n >= _Size)
281      __throw_out_of_range("array::at");
282    return __elems_[__n];
283  }
284
285  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference front() _NOEXCEPT { return (*this)[0]; }
286  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference front() const _NOEXCEPT { return (*this)[0]; }
287  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference back() _NOEXCEPT { return (*this)[_Size - 1]; }
288  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference back() const _NOEXCEPT {
289    return (*this)[_Size - 1];
290  }
291
292  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 value_type* data() _NOEXCEPT { return __elems_; }
293  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const value_type* data() const _NOEXCEPT { return __elems_; }
294};
295
296template <class _Tp>
297struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0> {
298  // types:
299  using __self          = array;
300  using value_type      = _Tp;
301  using reference       = value_type&;
302  using const_reference = const value_type&;
303  using pointer         = value_type*;
304  using const_pointer   = const value_type*;
305#if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
306  using iterator       = __static_bounded_iter<pointer, 0>;
307  using const_iterator = __static_bounded_iter<const_pointer, 0>;
308#elif defined(_LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY)
309  using iterator       = __wrap_iter<pointer>;
310  using const_iterator = __wrap_iter<const_pointer>;
311#else
312  using iterator       = pointer;
313  using const_iterator = const_pointer;
314#endif
315  using size_type              = size_t;
316  using difference_type        = ptrdiff_t;
317  using reverse_iterator       = std::reverse_iterator<iterator>;
318  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
319
320  using _EmptyType = __conditional_t<is_const<_Tp>::value, const __empty, __empty>;
321
322  struct _ArrayInStructT {
323    _Tp __data_[1];
324  };
325  _ALIGNAS_TYPE(_ArrayInStructT) _EmptyType __elems_[sizeof(_ArrayInStructT)];
326
327  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 value_type* data() _NOEXCEPT { return nullptr; }
328  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const value_type* data() const _NOEXCEPT { return nullptr; }
329
330  // No explicit construct/copy/destroy for aggregate type
331  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void fill(const value_type&) {
332    static_assert(!is_const<_Tp>::value, "cannot fill zero-sized array of type 'const T'");
333  }
334
335  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(array&) _NOEXCEPT {
336    static_assert(!is_const<_Tp>::value, "cannot swap zero-sized array of type 'const T'");
337  }
338
339  // iterators:
340  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator begin() _NOEXCEPT {
341#if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
342    return std::__make_static_bounded_iter<0>(data(), data());
343#else
344    return iterator(data());
345#endif
346  }
347  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator begin() const _NOEXCEPT {
348#if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
349    return std::__make_static_bounded_iter<0>(data(), data());
350#else
351    return const_iterator(data());
352#endif
353  }
354  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator end() _NOEXCEPT {
355#if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
356    return std::__make_static_bounded_iter<0>(data(), data());
357#else
358    return iterator(data());
359#endif
360  }
361  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator end() const _NOEXCEPT {
362#if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
363    return std::__make_static_bounded_iter<0>(data(), data());
364#else
365    return const_iterator(data());
366#endif
367  }
368
369  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rbegin() _NOEXCEPT {
370    return reverse_iterator(end());
371  }
372  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator rbegin() const _NOEXCEPT {
373    return const_reverse_iterator(end());
374  }
375  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rend() _NOEXCEPT {
376    return reverse_iterator(begin());
377  }
378  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator rend() const _NOEXCEPT {
379    return const_reverse_iterator(begin());
380  }
381
382  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cbegin() const _NOEXCEPT { return begin(); }
383  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cend() const _NOEXCEPT { return end(); }
384  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator crbegin() const _NOEXCEPT {
385    return rbegin();
386  }
387  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
388
389  // capacity:
390  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT { return 0; }
391  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT { return 0; }
392  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT { return true; }
393
394  // element access:
395  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference operator[](size_type) _NOEXCEPT {
396    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
397    __libcpp_unreachable();
398  }
399
400  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference operator[](size_type) const _NOEXCEPT {
401    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
402    __libcpp_unreachable();
403  }
404
405  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference at(size_type) {
406    __throw_out_of_range("array<T, 0>::at");
407    __libcpp_unreachable();
408  }
409
410  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference at(size_type) const {
411    __throw_out_of_range("array<T, 0>::at");
412    __libcpp_unreachable();
413  }
414
415  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference front() _NOEXCEPT {
416    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::front() on a zero-sized array");
417    __libcpp_unreachable();
418  }
419
420  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference front() const _NOEXCEPT {
421    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::front() on a zero-sized array");
422    __libcpp_unreachable();
423  }
424
425  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference back() _NOEXCEPT {
426    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::back() on a zero-sized array");
427    __libcpp_unreachable();
428  }
429
430  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference back() const _NOEXCEPT {
431    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(false, "cannot call array<T, 0>::back() on a zero-sized array");
432    __libcpp_unreachable();
433  }
434};
435
436#if _LIBCPP_STD_VER >= 17
437template <class _Tp, class... _Args, class = enable_if_t<__all<_IsSame<_Tp, _Args>::value...>::value> >
438array(_Tp, _Args...) -> array<_Tp, 1 + sizeof...(_Args)>;
439#endif
440
441template <class _Tp, size_t _Size>
442inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
443operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
444  return std::equal(__x.begin(), __x.end(), __y.begin());
445}
446
447#if _LIBCPP_STD_VER <= 17
448
449template <class _Tp, size_t _Size>
450inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
451  return !(__x == __y);
452}
453
454template <class _Tp, size_t _Size>
455inline _LIBCPP_HIDE_FROM_ABI bool operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
456  return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
457}
458
459template <class _Tp, size_t _Size>
460inline _LIBCPP_HIDE_FROM_ABI bool operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
461  return __y < __x;
462}
463
464template <class _Tp, size_t _Size>
465inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
466  return !(__y < __x);
467}
468
469template <class _Tp, size_t _Size>
470inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
471  return !(__x < __y);
472}
473
474#else // _LIBCPP_STD_VER <= 17
475
476template <class _Tp, size_t _Size>
477_LIBCPP_HIDE_FROM_ABI constexpr __synth_three_way_result<_Tp>
478operator<=>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
479  return std::lexicographical_compare_three_way(__x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);
480}
481
482#endif // _LIBCPP_STD_VER <= 17
483
484template <class _Tp, size_t _Size, __enable_if_t<_Size == 0 || __is_swappable_v<_Tp>, int> = 0>
485inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y)
486    _NOEXCEPT_(noexcept(__x.swap(__y))) {
487  __x.swap(__y);
488}
489
490template <class _Tp, size_t _Size>
491struct _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> > : public integral_constant<size_t, _Size> {};
492
493template <size_t _Ip, class _Tp, size_t _Size>
494struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> > {
495  static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)");
496  using type = _Tp;
497};
498
499template <size_t _Ip, class _Tp, size_t _Size>
500inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp& get(array<_Tp, _Size>& __a) _NOEXCEPT {
501  static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)");
502  return __a.__elems_[_Ip];
503}
504
505template <size_t _Ip, class _Tp, size_t _Size>
506inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp& get(const array<_Tp, _Size>& __a) _NOEXCEPT {
507  static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)");
508  return __a.__elems_[_Ip];
509}
510
511template <size_t _Ip, class _Tp, size_t _Size>
512inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp&& get(array<_Tp, _Size>&& __a) _NOEXCEPT {
513  static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)");
514  return std::move(__a.__elems_[_Ip]);
515}
516
517template <size_t _Ip, class _Tp, size_t _Size>
518inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&& get(const array<_Tp, _Size>&& __a) _NOEXCEPT {
519  static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)");
520  return std::move(__a.__elems_[_Ip]);
521}
522
523#if _LIBCPP_STD_VER >= 20
524
525template <typename _Tp, size_t _Size, size_t... _Index>
526_LIBCPP_HIDE_FROM_ABI constexpr array<remove_cv_t<_Tp>, _Size>
527__to_array_lvalue_impl(_Tp (&__arr)[_Size], index_sequence<_Index...>) {
528  return {{__arr[_Index]...}};
529}
530
531template <typename _Tp, size_t _Size, size_t... _Index>
532_LIBCPP_HIDE_FROM_ABI constexpr array<remove_cv_t<_Tp>, _Size>
533__to_array_rvalue_impl(_Tp (&&__arr)[_Size], index_sequence<_Index...>) {
534  return {{std::move(__arr[_Index])...}};
535}
536
537template <typename _Tp, size_t _Size>
538_LIBCPP_HIDE_FROM_ABI constexpr array<remove_cv_t<_Tp>, _Size>
539to_array(_Tp (&__arr)[_Size]) noexcept(is_nothrow_constructible_v<_Tp, _Tp&>) {
540  static_assert(!is_array_v<_Tp>, "[array.creation]/1: to_array does not accept multidimensional arrays.");
541  static_assert(is_constructible_v<_Tp, _Tp&>, "[array.creation]/1: to_array requires copy constructible elements.");
542  return std::__to_array_lvalue_impl(__arr, make_index_sequence<_Size>());
543}
544
545template <typename _Tp, size_t _Size>
546_LIBCPP_HIDE_FROM_ABI constexpr array<remove_cv_t<_Tp>, _Size>
547to_array(_Tp (&&__arr)[_Size]) noexcept(is_nothrow_move_constructible_v<_Tp>) {
548  static_assert(!is_array_v<_Tp>, "[array.creation]/4: to_array does not accept multidimensional arrays.");
549  static_assert(is_move_constructible_v<_Tp>, "[array.creation]/4: to_array requires move constructible elements.");
550  return std::__to_array_rvalue_impl(std::move(__arr), make_index_sequence<_Size>());
551}
552
553#endif // _LIBCPP_STD_VER >= 20
554
555_LIBCPP_END_NAMESPACE_STD
556
557_LIBCPP_POP_MACROS
558
559#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
560#  include <algorithm>
561#  include <concepts>
562#  include <cstdlib>
563#  include <iterator>
564#  include <type_traits>
565#  include <utility>
566#endif
567
568#endif // _LIBCPP_ARRAY
569