Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
Louis Dionne | 9bd9388 | 2021-11-17 16:25:01 -0500 | [diff] [blame] | 2 | //===----------------------------------------------------------------------===// |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3 | // |
Chandler Carruth | d201210 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_ARRAY |
| 11 | #define _LIBCPP_ARRAY |
| 12 | |
| 13 | /* |
| 14 | array synopsis |
| 15 | |
| 16 | namespace std |
| 17 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 18 | template <class T, size_t N > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 19 | struct array |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 20 | { |
| 21 | // types: |
| 22 | typedef T & reference; |
| 23 | typedef const T & const_reference; |
| 24 | typedef implementation defined iterator; |
| 25 | typedef implementation defined const_iterator; |
| 26 | typedef size_t size_type; |
| 27 | typedef ptrdiff_t difference_type; |
| 28 | typedef T value_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 29 | typedef T* pointer; |
| 30 | typedef const T* const_pointer; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 31 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 32 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 33 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 34 | // No explicit construct/copy/destroy for aggregate type |
Louis Dionne | 44704ce | 2020-05-22 09:59:48 -0400 | [diff] [blame] | 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 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 37 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 38 | // iterators: |
Louis Dionne | 44704ce | 2020-05-22 09:59:48 -0400 | [diff] [blame] | 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 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 43 | |
Louis Dionne | 44704ce | 2020-05-22 09:59:48 -0400 | [diff] [blame] | 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 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 48 | |
Louis Dionne | 44704ce | 2020-05-22 09:59:48 -0400 | [diff] [blame] | 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 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 53 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 54 | // capacity: |
Howard Hinnant | 32477e8 | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 55 | constexpr size_type size() const noexcept; |
| 56 | constexpr size_type max_size() const noexcept; |
Howard Hinnant | 12ff42f | 2012-07-20 19:20:49 +0000 | [diff] [blame] | 57 | constexpr bool empty() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 58 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 59 | // element access: |
Louis Dionne | 44704ce | 2020-05-22 09:59:48 -0400 | [diff] [blame] | 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 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 64 | |
Louis Dionne | 44704ce | 2020-05-22 09:59:48 -0400 | [diff] [blame] | 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 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 69 | |
Louis Dionne | 44704ce | 2020-05-22 09:59:48 -0400 | [diff] [blame] | 70 | T* data() noexcept; // constexpr in C++17 |
| 71 | const T* data() const noexcept; // constexpr in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 72 | }; |
| 73 | |
Louis Dionne | 44704ce | 2020-05-22 09:59:48 -0400 | [diff] [blame] | 74 | template <class T, class... U> |
| 75 | array(T, U...) -> array<T, 1 + sizeof...(U)>; // C++17 |
Marshall Clow | 8847d03 | 2018-05-18 21:01:04 +0000 | [diff] [blame] | 76 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 77 | template <class T, size_t N> |
Louis Dionne | 44704ce | 2020-05-22 09:59:48 -0400 | [diff] [blame] | 78 | bool operator==(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 79 | template <class T, size_t N> |
Louis Dionne | 44704ce | 2020-05-22 09:59:48 -0400 | [diff] [blame] | 80 | bool operator!=(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 81 | template <class T, size_t N> |
Louis Dionne | 44704ce | 2020-05-22 09:59:48 -0400 | [diff] [blame] | 82 | bool operator<(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 83 | template <class T, size_t N> |
Louis Dionne | 44704ce | 2020-05-22 09:59:48 -0400 | [diff] [blame] | 84 | bool operator>(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 85 | template <class T, size_t N> |
Louis Dionne | 44704ce | 2020-05-22 09:59:48 -0400 | [diff] [blame] | 86 | bool operator<=(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 87 | template <class T, size_t N> |
Louis Dionne | 44704ce | 2020-05-22 09:59:48 -0400 | [diff] [blame] | 88 | bool operator>=(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 89 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 90 | template <class T, size_t N > |
Louis Dionne | 44704ce | 2020-05-22 09:59:48 -0400 | [diff] [blame] | 91 | void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y))); // constexpr in C++20 |
| 92 | |
| 93 | template <class T, size_t N> |
| 94 | constexpr array<remove_cv_t<T>, N> to_array(T (&a)[N]); // C++20 |
| 95 | template <class T, size_t N> |
| 96 | constexpr array<remove_cv_t<T>, N> to_array(T (&&a)[N]); // C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 97 | |
Marshall Clow | ce62b4d | 2019-01-11 21:57:12 +0000 | [diff] [blame] | 98 | template <class T> struct tuple_size; |
Louis Dionne | e684aa6 | 2019-04-01 16:39:34 +0000 | [diff] [blame] | 99 | template <size_t I, class T> struct tuple_element; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 100 | template <class T, size_t N> struct tuple_size<array<T, N>>; |
Marshall Clow | 291a351 | 2015-11-19 19:41:04 +0000 | [diff] [blame] | 101 | template <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>; |
Louis Dionne | 44704ce | 2020-05-22 09:59:48 -0400 | [diff] [blame] | 102 | template <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14 |
| 103 | template <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++14 |
| 104 | template <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14 |
Eric Fiselier | 6dea809 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 105 | template <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 106 | |
| 107 | } // std |
| 108 | |
| 109 | */ |
| 110 | |
Nikolas Klauser | f210d8a | 2022-02-15 18:18:08 +0100 | [diff] [blame] | 111 | #include <__algorithm/equal.h> |
| 112 | #include <__algorithm/fill_n.h> |
| 113 | #include <__algorithm/lexicographical_compare.h> |
| 114 | #include <__algorithm/swap_ranges.h> |
Louis Dionne | b4fce35 | 2022-03-25 12:55:36 -0400 | [diff] [blame] | 115 | #include <__assert> // all public C++ headers provide the assertion handler |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 116 | #include <__config> |
Nikolas Klauser | fb1b067 | 2022-06-10 19:53:10 +0200 | [diff] [blame] | 117 | #include <__iterator/reverse_iterator.h> |
Michał Górny | 7cfb566 | 2022-12-04 07:39:41 +0100 | [diff] [blame^] | 118 | #include <__tuple_dir/sfinae_helpers.h> |
Nikolas Klauser | 8fccd62 | 2022-03-05 19:17:07 +0100 | [diff] [blame] | 119 | #include <__utility/integer_sequence.h> |
| 120 | #include <__utility/move.h> |
Nikolas Klauser | cfe2147 | 2022-02-14 18:26:02 +0100 | [diff] [blame] | 121 | #include <__utility/unreachable.h> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 122 | #include <stdexcept> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 123 | #include <type_traits> |
Marshall Clow | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 124 | #include <version> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 125 | |
Nikolas Klauser | a0e0edb | 2022-06-16 22:43:46 +0200 | [diff] [blame] | 126 | // standard-mandated includes |
| 127 | |
| 128 | // [iterator.range] |
| 129 | #include <__iterator/access.h> |
| 130 | #include <__iterator/data.h> |
| 131 | #include <__iterator/empty.h> |
| 132 | #include <__iterator/reverse_access.h> |
| 133 | #include <__iterator/size.h> |
| 134 | |
| 135 | // [array.syn] |
| 136 | #include <compare> |
| 137 | #include <initializer_list> |
| 138 | |
Nikolas Klauser | a22eabb | 2022-09-05 14:38:24 +0200 | [diff] [blame] | 139 | // [tuple.helper] |
Michał Górny | 7cfb566 | 2022-12-04 07:39:41 +0100 | [diff] [blame^] | 140 | #include <__tuple_dir/tuple_element.h> |
| 141 | #include <__tuple_dir/tuple_size.h> |
Nikolas Klauser | a22eabb | 2022-09-05 14:38:24 +0200 | [diff] [blame] | 142 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 143 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Arthur O'Dwyer | 6eeaa00 | 2022-02-01 20:16:40 -0500 | [diff] [blame] | 144 | # pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 145 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 146 | |
| 147 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 148 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 149 | template <class _Tp, size_t _Size> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 150 | struct _LIBCPP_TEMPLATE_VIS array |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 151 | { |
| 152 | // types: |
| 153 | typedef array __self; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 154 | typedef _Tp value_type; |
| 155 | typedef value_type& reference; |
| 156 | typedef const value_type& const_reference; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 157 | typedef value_type* iterator; |
| 158 | typedef const value_type* const_iterator; |
| 159 | typedef value_type* pointer; |
| 160 | typedef const value_type* const_pointer; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 161 | typedef size_t size_type; |
| 162 | typedef ptrdiff_t difference_type; |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 163 | typedef _VSTD::reverse_iterator<iterator> reverse_iterator; |
| 164 | typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 165 | |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 166 | _Tp __elems_[_Size]; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 167 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 168 | // No explicit construct/copy/destroy for aggregate type |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 169 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 44704ce | 2020-05-22 09:59:48 -0400 | [diff] [blame] | 170 | void fill(const value_type& __u) { |
Louis Dionne | 7e10cd2 | 2020-06-01 16:28:44 -0400 | [diff] [blame] | 171 | _VSTD::fill_n(data(), _Size, __u); |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 172 | } |
Eric Fiselier | 55659e4 | 2018-02-04 01:03:08 +0000 | [diff] [blame] | 173 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 174 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 175 | void swap(array& __a) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) { |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 176 | _VSTD::swap_ranges(data(), data() + _Size, __a.data()); |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 177 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 178 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 179 | // iterators: |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 180 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 181 | iterator begin() _NOEXCEPT {return iterator(data());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 182 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 183 | const_iterator begin() const _NOEXCEPT {return const_iterator(data());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 184 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 185 | iterator end() _NOEXCEPT {return iterator(data() + _Size);} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 186 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 187 | const_iterator end() const _NOEXCEPT {return const_iterator(data() + _Size);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 188 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 189 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Howard Hinnant | 32477e8 | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 190 | reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 191 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Howard Hinnant | 32477e8 | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 192 | const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 193 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Howard Hinnant | 32477e8 | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 194 | reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 195 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Howard Hinnant | 32477e8 | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 196 | const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 197 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 198 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Howard Hinnant | 32477e8 | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 199 | const_iterator cbegin() const _NOEXCEPT {return begin();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 200 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Howard Hinnant | 32477e8 | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 201 | const_iterator cend() const _NOEXCEPT {return end();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 202 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Howard Hinnant | 32477e8 | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 203 | const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 204 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Howard Hinnant | 32477e8 | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 205 | const_reverse_iterator crend() const _NOEXCEPT {return rend();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 206 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 207 | // capacity: |
Howard Hinnant | 32477e8 | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 208 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 12ff42f | 2012-07-20 19:20:49 +0000 | [diff] [blame] | 209 | _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;} |
Howard Hinnant | 32477e8 | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 210 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 12ff42f | 2012-07-20 19:20:49 +0000 | [diff] [blame] | 211 | _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;} |
Marshall Clow | 425f575 | 2017-11-15 05:51:26 +0000 | [diff] [blame] | 212 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | 7e10cd2 | 2020-06-01 16:28:44 -0400 | [diff] [blame] | 213 | _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return _Size == 0;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 214 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 215 | // element access: |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 216 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Louis Dionne | ed04d17 | 2020-06-01 16:35:42 -0400 | [diff] [blame] | 217 | reference operator[](size_type __n) _NOEXCEPT { |
| 218 | _LIBCPP_ASSERT(__n < _Size, "out-of-bounds access in std::array<T, N>"); |
| 219 | return __elems_[__n]; |
| 220 | } |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 221 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 |
Louis Dionne | ed04d17 | 2020-06-01 16:35:42 -0400 | [diff] [blame] | 222 | const_reference operator[](size_type __n) const _NOEXCEPT { |
| 223 | _LIBCPP_ASSERT(__n < _Size, "out-of-bounds access in std::array<T, N>"); |
| 224 | return __elems_[__n]; |
| 225 | } |
Marshall Clow | ac63f41 | 2017-01-16 03:02:10 +0000 | [diff] [blame] | 226 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 227 | _LIBCPP_CONSTEXPR_SINCE_CXX17 reference at(size_type __n) |
Louis Dionne | 8468f97 | 2020-05-22 09:23:32 -0400 | [diff] [blame] | 228 | { |
| 229 | if (__n >= _Size) |
| 230 | __throw_out_of_range("array::at"); |
| 231 | return __elems_[__n]; |
| 232 | } |
| 233 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 234 | _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference at(size_type __n) const |
Louis Dionne | 8468f97 | 2020-05-22 09:23:32 -0400 | [diff] [blame] | 235 | { |
| 236 | if (__n >= _Size) |
| 237 | __throw_out_of_range("array::at"); |
| 238 | return __elems_[__n]; |
| 239 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 240 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 241 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 reference front() _NOEXCEPT {return (*this)[0];} |
| 242 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference front() const _NOEXCEPT {return (*this)[0];} |
| 243 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 reference back() _NOEXCEPT {return (*this)[_Size - 1];} |
| 244 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference back() const _NOEXCEPT {return (*this)[_Size - 1];} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 245 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 246 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Nirav Dave | 129fb5c | 2018-02-06 03:03:37 +0000 | [diff] [blame] | 247 | value_type* data() _NOEXCEPT {return __elems_;} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 248 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Nirav Dave | 129fb5c | 2018-02-06 03:03:37 +0000 | [diff] [blame] | 249 | const value_type* data() const _NOEXCEPT {return __elems_;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 250 | }; |
| 251 | |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 252 | template <class _Tp> |
| 253 | struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0> |
| 254 | { |
| 255 | // types: |
| 256 | typedef array __self; |
| 257 | typedef _Tp value_type; |
| 258 | typedef value_type& reference; |
| 259 | typedef const value_type& const_reference; |
| 260 | typedef value_type* iterator; |
| 261 | typedef const value_type* const_iterator; |
| 262 | typedef value_type* pointer; |
| 263 | typedef const value_type* const_pointer; |
| 264 | typedef size_t size_type; |
| 265 | typedef ptrdiff_t difference_type; |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 266 | typedef _VSTD::reverse_iterator<iterator> reverse_iterator; |
| 267 | typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 268 | |
Nikolas Klauser | 72800ce | 2022-10-01 15:42:00 +0200 | [diff] [blame] | 269 | typedef __conditional_t<is_const<_Tp>::value, const char, char> _CharType; |
Eric Fiselier | 6a53758 | 2018-02-07 23:50:25 +0000 | [diff] [blame] | 270 | |
| 271 | struct _ArrayInStructT { _Tp __data_[1]; }; |
| 272 | _ALIGNAS_TYPE(_ArrayInStructT) _CharType __elems_[sizeof(_ArrayInStructT)]; |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 273 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 274 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Louis Dionne | c5647ff | 2020-05-29 16:32:55 -0700 | [diff] [blame] | 275 | value_type* data() _NOEXCEPT {return nullptr;} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 276 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Louis Dionne | c5647ff | 2020-05-29 16:32:55 -0700 | [diff] [blame] | 277 | const value_type* data() const _NOEXCEPT {return nullptr;} |
Louis Dionne | 44704ce | 2020-05-22 09:59:48 -0400 | [diff] [blame] | 278 | |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 279 | // No explicit construct/copy/destroy for aggregate type |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 280 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 44704ce | 2020-05-22 09:59:48 -0400 | [diff] [blame] | 281 | void fill(const value_type&) { |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 282 | static_assert(!is_const<_Tp>::value, |
| 283 | "cannot fill zero-sized array of type 'const T'"); |
| 284 | } |
| 285 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 286 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 287 | void swap(array&) _NOEXCEPT { |
| 288 | static_assert(!is_const<_Tp>::value, |
| 289 | "cannot swap zero-sized array of type 'const T'"); |
| 290 | } |
| 291 | |
| 292 | // iterators: |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 293 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 294 | iterator begin() _NOEXCEPT {return iterator(data());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 295 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 296 | const_iterator begin() const _NOEXCEPT {return const_iterator(data());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 297 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 298 | iterator end() _NOEXCEPT {return iterator(data());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 299 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 300 | const_iterator end() const _NOEXCEPT {return const_iterator(data());} |
| 301 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 302 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 303 | reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 304 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 305 | const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 306 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 307 | reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 308 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 309 | const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());} |
| 310 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 311 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 312 | const_iterator cbegin() const _NOEXCEPT {return begin();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 313 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 314 | const_iterator cend() const _NOEXCEPT {return end();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 315 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 316 | const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 317 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 318 | const_reverse_iterator crend() const _NOEXCEPT {return rend();} |
| 319 | |
| 320 | // capacity: |
| 321 | _LIBCPP_INLINE_VISIBILITY |
| 322 | _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return 0; } |
| 323 | _LIBCPP_INLINE_VISIBILITY |
| 324 | _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return 0;} |
| 325 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
| 326 | _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return true;} |
| 327 | |
| 328 | // element access: |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 329 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Marshall Clow | 8d7c9f1 | 2019-03-14 21:56:57 +0000 | [diff] [blame] | 330 | reference operator[](size_type) _NOEXCEPT { |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 331 | _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array"); |
Nikolas Klauser | cfe2147 | 2022-02-14 18:26:02 +0100 | [diff] [blame] | 332 | __libcpp_unreachable(); |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 333 | } |
| 334 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 335 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 |
Marshall Clow | 8d7c9f1 | 2019-03-14 21:56:57 +0000 | [diff] [blame] | 336 | const_reference operator[](size_type) const _NOEXCEPT { |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 337 | _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array"); |
Nikolas Klauser | cfe2147 | 2022-02-14 18:26:02 +0100 | [diff] [blame] | 338 | __libcpp_unreachable(); |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 339 | } |
| 340 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 341 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 342 | reference at(size_type) { |
| 343 | __throw_out_of_range("array<T, 0>::at"); |
Nikolas Klauser | cfe2147 | 2022-02-14 18:26:02 +0100 | [diff] [blame] | 344 | __libcpp_unreachable(); |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 345 | } |
| 346 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 347 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 348 | const_reference at(size_type) const { |
| 349 | __throw_out_of_range("array<T, 0>::at"); |
Nikolas Klauser | cfe2147 | 2022-02-14 18:26:02 +0100 | [diff] [blame] | 350 | __libcpp_unreachable(); |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 351 | } |
| 352 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 353 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Marshall Clow | 05cf669 | 2019-03-19 03:30:07 +0000 | [diff] [blame] | 354 | reference front() _NOEXCEPT { |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 355 | _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array"); |
Nikolas Klauser | cfe2147 | 2022-02-14 18:26:02 +0100 | [diff] [blame] | 356 | __libcpp_unreachable(); |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 359 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 |
Marshall Clow | 05cf669 | 2019-03-19 03:30:07 +0000 | [diff] [blame] | 360 | const_reference front() const _NOEXCEPT { |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 361 | _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array"); |
Nikolas Klauser | cfe2147 | 2022-02-14 18:26:02 +0100 | [diff] [blame] | 362 | __libcpp_unreachable(); |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 365 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Marshall Clow | 05cf669 | 2019-03-19 03:30:07 +0000 | [diff] [blame] | 366 | reference back() _NOEXCEPT { |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 367 | _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array"); |
Nikolas Klauser | cfe2147 | 2022-02-14 18:26:02 +0100 | [diff] [blame] | 368 | __libcpp_unreachable(); |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 371 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 |
Marshall Clow | 05cf669 | 2019-03-19 03:30:07 +0000 | [diff] [blame] | 372 | const_reference back() const _NOEXCEPT { |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 373 | _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array"); |
Nikolas Klauser | cfe2147 | 2022-02-14 18:26:02 +0100 | [diff] [blame] | 374 | __libcpp_unreachable(); |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 375 | } |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 376 | }; |
| 377 | |
| 378 | |
Nikolas Klauser | cfe2147 | 2022-02-14 18:26:02 +0100 | [diff] [blame] | 379 | #if _LIBCPP_STD_VER > 14 |
Marshall Clow | 8847d03 | 2018-05-18 21:01:04 +0000 | [diff] [blame] | 380 | template<class _Tp, class... _Args, |
Louis Dionne | 2554716 | 2021-08-17 12:26:09 -0400 | [diff] [blame] | 381 | class = enable_if_t<__all<_IsSame<_Tp, _Args>::value...>::value> |
Marshall Clow | 8847d03 | 2018-05-18 21:01:04 +0000 | [diff] [blame] | 382 | > |
| 383 | array(_Tp, _Args...) |
| 384 | -> array<_Tp, 1 + sizeof...(_Args)>; |
| 385 | #endif |
| 386 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 387 | template <class _Tp, size_t _Size> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 388 | inline _LIBCPP_INLINE_VISIBILITY |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 389 | _LIBCPP_CONSTEXPR_SINCE_CXX20 bool |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 390 | operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) |
| 391 | { |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 392 | return _VSTD::equal(__x.begin(), __x.end(), __y.begin()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 393 | } |
| 394 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 395 | template <class _Tp, size_t _Size> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 396 | inline _LIBCPP_INLINE_VISIBILITY |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 397 | _LIBCPP_CONSTEXPR_SINCE_CXX20 bool |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 398 | operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) |
| 399 | { |
| 400 | return !(__x == __y); |
| 401 | } |
| 402 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 403 | template <class _Tp, size_t _Size> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 404 | inline _LIBCPP_INLINE_VISIBILITY |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 405 | _LIBCPP_CONSTEXPR_SINCE_CXX20 bool |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 406 | operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) |
| 407 | { |
Eric Fiselier | 5037a3b | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 408 | return _VSTD::lexicographical_compare(__x.begin(), __x.end(), |
| 409 | __y.begin(), __y.end()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 410 | } |
| 411 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 412 | template <class _Tp, size_t _Size> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 413 | inline _LIBCPP_INLINE_VISIBILITY |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 414 | _LIBCPP_CONSTEXPR_SINCE_CXX20 bool |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 415 | operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) |
| 416 | { |
| 417 | return __y < __x; |
| 418 | } |
| 419 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 420 | template <class _Tp, size_t _Size> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 421 | inline _LIBCPP_INLINE_VISIBILITY |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 422 | _LIBCPP_CONSTEXPR_SINCE_CXX20 bool |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 423 | operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) |
| 424 | { |
| 425 | return !(__y < __x); |
| 426 | } |
| 427 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 428 | template <class _Tp, size_t _Size> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 429 | inline _LIBCPP_INLINE_VISIBILITY |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 430 | _LIBCPP_CONSTEXPR_SINCE_CXX20 bool |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 431 | operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) |
| 432 | { |
| 433 | return !(__x < __y); |
| 434 | } |
| 435 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 436 | template <class _Tp, size_t _Size> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 437 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 7537c9c | 2022-07-04 01:21:44 +0200 | [diff] [blame] | 438 | __enable_if_t<_Size == 0 || __is_swappable<_Tp>::value, void> |
Marshall Clow | ff1aa3d | 2016-03-07 21:57:10 +0000 | [diff] [blame] | 439 | swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y) |
Eric Fiselier | 6bfed25 | 2016-04-21 23:38:59 +0000 | [diff] [blame] | 440 | _NOEXCEPT_(noexcept(__x.swap(__y))) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 441 | { |
| 442 | __x.swap(__y); |
| 443 | } |
| 444 | |
| 445 | template <class _Tp, size_t _Size> |
Marshall Clow | ce62b4d | 2019-01-11 21:57:12 +0000 | [diff] [blame] | 446 | struct _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> > |
Howard Hinnant | 8e29cda | 2010-09-21 20:16:37 +0000 | [diff] [blame] | 447 | : public integral_constant<size_t, _Size> {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 448 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 449 | template <size_t _Ip, class _Tp, size_t _Size> |
Louis Dionne | e684aa6 | 2019-04-01 16:39:34 +0000 | [diff] [blame] | 450 | struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 451 | { |
Marshall Clow | 6f77fa1 | 2017-06-12 14:41:37 +0000 | [diff] [blame] | 452 | static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 453 | typedef _Tp type; |
| 454 | }; |
| 455 | |
| 456 | template <size_t _Ip, class _Tp, size_t _Size> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 457 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 458 | _Tp& |
Howard Hinnant | 32477e8 | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 459 | get(array<_Tp, _Size>& __a) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 460 | { |
Marshall Clow | 66c49ca | 2012-12-18 16:46:30 +0000 | [diff] [blame] | 461 | static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)"); |
Marshall Clow | 0abb104 | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 462 | return __a.__elems_[_Ip]; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | template <size_t _Ip, class _Tp, size_t _Size> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 466 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 467 | const _Tp& |
Howard Hinnant | 32477e8 | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 468 | get(const array<_Tp, _Size>& __a) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 469 | { |
Marshall Clow | 66c49ca | 2012-12-18 16:46:30 +0000 | [diff] [blame] | 470 | static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)"); |
Marshall Clow | 0abb104 | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 471 | return __a.__elems_[_Ip]; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 472 | } |
| 473 | |
Howard Hinnant | 22e9724 | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 474 | template <size_t _Ip, class _Tp, size_t _Size> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 475 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 |
Howard Hinnant | 22e9724 | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 476 | _Tp&& |
Howard Hinnant | 32477e8 | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 477 | get(array<_Tp, _Size>&& __a) _NOEXCEPT |
Howard Hinnant | 22e9724 | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 478 | { |
Marshall Clow | 66c49ca | 2012-12-18 16:46:30 +0000 | [diff] [blame] | 479 | static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)"); |
Marshall Clow | 0abb104 | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 480 | return _VSTD::move(__a.__elems_[_Ip]); |
Howard Hinnant | 22e9724 | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 481 | } |
| 482 | |
Eric Fiselier | 6dea809 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 483 | template <size_t _Ip, class _Tp, size_t _Size> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 484 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 |
Eric Fiselier | 6dea809 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 485 | const _Tp&& |
| 486 | get(const array<_Tp, _Size>&& __a) _NOEXCEPT |
| 487 | { |
| 488 | static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)"); |
| 489 | return _VSTD::move(__a.__elems_[_Ip]); |
| 490 | } |
| 491 | |
Marek Kurdej | 0d71567 | 2020-01-30 13:27:35 +0100 | [diff] [blame] | 492 | #if _LIBCPP_STD_VER > 17 |
| 493 | |
| 494 | template <typename _Tp, size_t _Size, size_t... _Index> |
| 495 | _LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size> |
| 496 | __to_array_lvalue_impl(_Tp (&__arr)[_Size], index_sequence<_Index...>) { |
| 497 | return {{__arr[_Index]...}}; |
| 498 | } |
| 499 | |
| 500 | template <typename _Tp, size_t _Size, size_t... _Index> |
| 501 | _LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size> |
| 502 | __to_array_rvalue_impl(_Tp(&&__arr)[_Size], index_sequence<_Index...>) { |
| 503 | return {{_VSTD::move(__arr[_Index])...}}; |
| 504 | } |
| 505 | |
| 506 | template <typename _Tp, size_t _Size> |
| 507 | _LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size> |
| 508 | to_array(_Tp (&__arr)[_Size]) noexcept(is_nothrow_constructible_v<_Tp, _Tp&>) { |
| 509 | static_assert( |
| 510 | !is_array_v<_Tp>, |
| 511 | "[array.creation]/1: to_array does not accept multidimensional arrays."); |
| 512 | static_assert( |
| 513 | is_constructible_v<_Tp, _Tp&>, |
| 514 | "[array.creation]/1: to_array requires copy constructible elements."); |
Arthur O'Dwyer | 34465da | 2020-12-15 19:32:29 -0500 | [diff] [blame] | 515 | return _VSTD::__to_array_lvalue_impl(__arr, make_index_sequence<_Size>()); |
Marek Kurdej | 0d71567 | 2020-01-30 13:27:35 +0100 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | template <typename _Tp, size_t _Size> |
| 519 | _LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size> |
| 520 | to_array(_Tp(&&__arr)[_Size]) noexcept(is_nothrow_move_constructible_v<_Tp>) { |
| 521 | static_assert( |
| 522 | !is_array_v<_Tp>, |
| 523 | "[array.creation]/4: to_array does not accept multidimensional arrays."); |
| 524 | static_assert( |
| 525 | is_move_constructible_v<_Tp>, |
| 526 | "[array.creation]/4: to_array requires move constructible elements."); |
Arthur O'Dwyer | 34465da | 2020-12-15 19:32:29 -0500 | [diff] [blame] | 527 | return _VSTD::__to_array_rvalue_impl(_VSTD::move(__arr), |
| 528 | make_index_sequence<_Size>()); |
Marek Kurdej | 0d71567 | 2020-01-30 13:27:35 +0100 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | #endif // _LIBCPP_STD_VER > 17 |
| 532 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 533 | _LIBCPP_END_NAMESPACE_STD |
| 534 | |
Mark de Wever | ee5fe27 | 2022-09-02 17:53:28 +0200 | [diff] [blame] | 535 | #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 |
| 536 | # include <algorithm> |
Nikolas Klauser | 1e4ae5d | 2022-11-02 20:27:42 +0100 | [diff] [blame] | 537 | # include <concepts> |
Mark de Wever | ee5fe27 | 2022-09-02 17:53:28 +0200 | [diff] [blame] | 538 | # include <iterator> |
| 539 | # include <utility> |
| 540 | #endif |
| 541 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 542 | #endif // _LIBCPP_ARRAY |