| 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 | |
| 16 | namespace std |
| 17 | { |
| 18 | template <class T, size_t N > |
| 19 | struct array |
| 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; |
| 29 | typedef T* pointer; |
| 30 | typedef const T* const_pointer; |
| 31 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 32 | typedef std::reverse_iterator<const_iterator> const_reverse_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 | |
| 74 | template <class T, class... U> |
| 75 | array(T, U...) -> array<T, 1 + sizeof...(U)>; // C++17 |
| 76 | |
| 77 | template <class T, size_t N> |
| 78 | bool operator==(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 |
| 79 | template <class T, size_t N> |
| 80 | bool operator!=(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 |
| 81 | template <class T, size_t N> |
| 82 | bool operator<(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 |
| 83 | template <class T, size_t N> |
| 84 | bool operator>(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 |
| 85 | template <class T, size_t N> |
| 86 | bool operator<=(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 |
| 87 | template <class T, size_t N> |
| 88 | bool operator>=(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 |
| 89 | |
| 90 | template <class T, size_t N > |
| 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 |
| 97 | |
| 98 | template <class T> struct tuple_size; |
| 99 | template <size_t I, class T> struct tuple_element; |
| 100 | template <class T, size_t N> struct tuple_size<array<T, N>>; |
| 101 | template <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>; |
| 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 |
| 105 | template <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14 |
| 106 | |
| 107 | } // std |
| 108 | |
| 109 | */ |
| 110 | |
| 111 | #include <__algorithm/equal.h> |
| 112 | #include <__algorithm/fill_n.h> |
| 113 | #include <__algorithm/lexicographical_compare.h> |
| 114 | #include <__algorithm/swap_ranges.h> |
| 115 | #include <__assert> // all public C++ headers provide the assertion handler |
| 116 | #include <__config> |
| 117 | #include <__iterator/reverse_iterator.h> |
| 118 | #include <__tuple> |
| 119 | #include <__utility/integer_sequence.h> |
| 120 | #include <__utility/move.h> |
| 121 | #include <__utility/unreachable.h> |
| 122 | #include <stdexcept> |
| 123 | #include <type_traits> |
| 124 | #include <version> |
| 125 | |
| 126 | #ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES |
| 127 | # include <algorithm> |
| 128 | # include <iterator> |
| 129 | # include <utility> |
| 130 | #endif |
| 131 | |
| 132 | // standard-mandated includes |
| 133 | |
| 134 | // [iterator.range] |
| 135 | #include <__iterator/access.h> |
| 136 | #include <__iterator/data.h> |
| 137 | #include <__iterator/empty.h> |
| 138 | #include <__iterator/reverse_access.h> |
| 139 | #include <__iterator/size.h> |
| 140 | |
| 141 | // [array.syn] |
| 142 | #include <compare> |
| 143 | #include <initializer_list> |
| 144 | |
| 145 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 146 | # pragma GCC system_header |
| 147 | #endif |
| 148 | |
| 149 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 150 | |
| 151 | template <class _Tp, size_t _Size> |
| 152 | struct _LIBCPP_TEMPLATE_VIS array |
| 153 | { |
| 154 | // types: |
| 155 | typedef array __self; |
| 156 | typedef _Tp value_type; |
| 157 | typedef value_type& reference; |
| 158 | typedef const value_type& const_reference; |
| 159 | typedef value_type* iterator; |
| 160 | typedef const value_type* const_iterator; |
| 161 | typedef value_type* pointer; |
| 162 | typedef const value_type* const_pointer; |
| 163 | typedef size_t size_type; |
| 164 | typedef ptrdiff_t difference_type; |
| 165 | typedef _VSTD::reverse_iterator<iterator> reverse_iterator; |
| 166 | typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; |
| 167 | |
| 168 | _Tp __elems_[_Size]; |
| 169 | |
| 170 | // No explicit construct/copy/destroy for aggregate type |
| 171 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 172 | void fill(const value_type& __u) { |
| 173 | _VSTD::fill_n(data(), _Size, __u); |
| 174 | } |
| 175 | |
| 176 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 177 | void swap(array& __a) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) { |
| 178 | _VSTD::swap_ranges(data(), data() + _Size, __a.data()); |
| 179 | } |
| 180 | |
| 181 | // iterators: |
| 182 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 183 | iterator begin() _NOEXCEPT {return iterator(data());} |
| 184 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 185 | const_iterator begin() const _NOEXCEPT {return const_iterator(data());} |
| 186 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 187 | iterator end() _NOEXCEPT {return iterator(data() + _Size);} |
| 188 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 189 | const_iterator end() const _NOEXCEPT {return const_iterator(data() + _Size);} |
| 190 | |
| 191 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 192 | reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} |
| 193 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 194 | const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());} |
| 195 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 196 | reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} |
| 197 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 198 | const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());} |
| 199 | |
| 200 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 201 | const_iterator cbegin() const _NOEXCEPT {return begin();} |
| 202 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 203 | const_iterator cend() const _NOEXCEPT {return end();} |
| 204 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 205 | const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} |
| 206 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 207 | const_reverse_iterator crend() const _NOEXCEPT {return rend();} |
| 208 | |
| 209 | // capacity: |
| 210 | _LIBCPP_INLINE_VISIBILITY |
| 211 | _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;} |
| 212 | _LIBCPP_INLINE_VISIBILITY |
| 213 | _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;} |
| 214 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
| 215 | _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return _Size == 0;} |
| 216 | |
| 217 | // element access: |
| 218 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 219 | reference operator[](size_type __n) _NOEXCEPT { |
| 220 | _LIBCPP_ASSERT(__n < _Size, "out-of-bounds access in std::array<T, N>" ); |
| 221 | return __elems_[__n]; |
| 222 | } |
| 223 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 224 | const_reference operator[](size_type __n) const _NOEXCEPT { |
| 225 | _LIBCPP_ASSERT(__n < _Size, "out-of-bounds access in std::array<T, N>" ); |
| 226 | return __elems_[__n]; |
| 227 | } |
| 228 | |
| 229 | _LIBCPP_CONSTEXPR_AFTER_CXX14 reference at(size_type __n) |
| 230 | { |
| 231 | if (__n >= _Size) |
| 232 | __throw_out_of_range(msg: "array::at" ); |
| 233 | return __elems_[__n]; |
| 234 | } |
| 235 | |
| 236 | _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const |
| 237 | { |
| 238 | if (__n >= _Size) |
| 239 | __throw_out_of_range(msg: "array::at" ); |
| 240 | return __elems_[__n]; |
| 241 | } |
| 242 | |
| 243 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front() _NOEXCEPT {return (*this)[0];} |
| 244 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const _NOEXCEPT {return (*this)[0];} |
| 245 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back() _NOEXCEPT {return (*this)[_Size - 1];} |
| 246 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const _NOEXCEPT {return (*this)[_Size - 1];} |
| 247 | |
| 248 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 249 | value_type* data() _NOEXCEPT {return __elems_;} |
| 250 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 251 | const value_type* data() const _NOEXCEPT {return __elems_;} |
| 252 | }; |
| 253 | |
| 254 | template <class _Tp> |
| 255 | struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0> |
| 256 | { |
| 257 | // types: |
| 258 | typedef array __self; |
| 259 | typedef _Tp value_type; |
| 260 | typedef value_type& reference; |
| 261 | typedef const value_type& const_reference; |
| 262 | typedef value_type* iterator; |
| 263 | typedef const value_type* const_iterator; |
| 264 | typedef value_type* pointer; |
| 265 | typedef const value_type* const_pointer; |
| 266 | typedef size_t size_type; |
| 267 | typedef ptrdiff_t difference_type; |
| 268 | typedef _VSTD::reverse_iterator<iterator> reverse_iterator; |
| 269 | typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; |
| 270 | |
| 271 | typedef typename conditional<is_const<_Tp>::value, const char, |
| 272 | char>::type _CharType; |
| 273 | |
| 274 | struct _ArrayInStructT { _Tp __data_[1]; }; |
| 275 | _ALIGNAS_TYPE(_ArrayInStructT) _CharType __elems_[sizeof(_ArrayInStructT)]; |
| 276 | |
| 277 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 278 | value_type* data() _NOEXCEPT {return nullptr;} |
| 279 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 280 | const value_type* data() const _NOEXCEPT {return nullptr;} |
| 281 | |
| 282 | // No explicit construct/copy/destroy for aggregate type |
| 283 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 284 | void fill(const value_type&) { |
| 285 | static_assert(!is_const<_Tp>::value, |
| 286 | "cannot fill zero-sized array of type 'const T'" ); |
| 287 | } |
| 288 | |
| 289 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 290 | void swap(array&) _NOEXCEPT { |
| 291 | static_assert(!is_const<_Tp>::value, |
| 292 | "cannot swap zero-sized array of type 'const T'" ); |
| 293 | } |
| 294 | |
| 295 | // iterators: |
| 296 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 297 | iterator begin() _NOEXCEPT {return iterator(data());} |
| 298 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 299 | const_iterator begin() const _NOEXCEPT {return const_iterator(data());} |
| 300 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 301 | iterator end() _NOEXCEPT {return iterator(data());} |
| 302 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 303 | const_iterator end() const _NOEXCEPT {return const_iterator(data());} |
| 304 | |
| 305 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 306 | reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} |
| 307 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 308 | const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());} |
| 309 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 310 | reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} |
| 311 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 312 | const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());} |
| 313 | |
| 314 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 315 | const_iterator cbegin() const _NOEXCEPT {return begin();} |
| 316 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 317 | const_iterator cend() const _NOEXCEPT {return end();} |
| 318 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 319 | const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} |
| 320 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 321 | const_reverse_iterator crend() const _NOEXCEPT {return rend();} |
| 322 | |
| 323 | // capacity: |
| 324 | _LIBCPP_INLINE_VISIBILITY |
| 325 | _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return 0; } |
| 326 | _LIBCPP_INLINE_VISIBILITY |
| 327 | _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return 0;} |
| 328 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
| 329 | _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return true;} |
| 330 | |
| 331 | // element access: |
| 332 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 333 | reference operator[](size_type) _NOEXCEPT { |
| 334 | _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array" ); |
| 335 | __libcpp_unreachable(); |
| 336 | } |
| 337 | |
| 338 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 339 | const_reference operator[](size_type) const _NOEXCEPT { |
| 340 | _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array" ); |
| 341 | __libcpp_unreachable(); |
| 342 | } |
| 343 | |
| 344 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 345 | reference at(size_type) { |
| 346 | __throw_out_of_range(msg: "array<T, 0>::at" ); |
| 347 | __libcpp_unreachable(); |
| 348 | } |
| 349 | |
| 350 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 351 | const_reference at(size_type) const { |
| 352 | __throw_out_of_range(msg: "array<T, 0>::at" ); |
| 353 | __libcpp_unreachable(); |
| 354 | } |
| 355 | |
| 356 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 357 | reference front() _NOEXCEPT { |
| 358 | _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array" ); |
| 359 | __libcpp_unreachable(); |
| 360 | } |
| 361 | |
| 362 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 363 | const_reference front() const _NOEXCEPT { |
| 364 | _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array" ); |
| 365 | __libcpp_unreachable(); |
| 366 | } |
| 367 | |
| 368 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 369 | reference back() _NOEXCEPT { |
| 370 | _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array" ); |
| 371 | __libcpp_unreachable(); |
| 372 | } |
| 373 | |
| 374 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 375 | const_reference back() const _NOEXCEPT { |
| 376 | _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array" ); |
| 377 | __libcpp_unreachable(); |
| 378 | } |
| 379 | }; |
| 380 | |
| 381 | |
| 382 | #if _LIBCPP_STD_VER > 14 |
| 383 | template<class _Tp, class... _Args, |
| 384 | class = enable_if_t<__all<_IsSame<_Tp, _Args>::value...>::value> |
| 385 | > |
| 386 | array(_Tp, _Args...) |
| 387 | -> array<_Tp, 1 + sizeof...(_Args)>; |
| 388 | #endif |
| 389 | |
| 390 | template <class _Tp, size_t _Size> |
| 391 | inline _LIBCPP_INLINE_VISIBILITY |
| 392 | _LIBCPP_CONSTEXPR_AFTER_CXX17 bool |
| 393 | operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) |
| 394 | { |
| 395 | return _VSTD::equal(__x.begin(), __x.end(), __y.begin()); |
| 396 | } |
| 397 | |
| 398 | template <class _Tp, size_t _Size> |
| 399 | inline _LIBCPP_INLINE_VISIBILITY |
| 400 | _LIBCPP_CONSTEXPR_AFTER_CXX17 bool |
| 401 | operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) |
| 402 | { |
| 403 | return !(__x == __y); |
| 404 | } |
| 405 | |
| 406 | template <class _Tp, size_t _Size> |
| 407 | inline _LIBCPP_INLINE_VISIBILITY |
| 408 | _LIBCPP_CONSTEXPR_AFTER_CXX17 bool |
| 409 | operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) |
| 410 | { |
| 411 | return _VSTD::lexicographical_compare(__x.begin(), __x.end(), |
| 412 | __y.begin(), __y.end()); |
| 413 | } |
| 414 | |
| 415 | template <class _Tp, size_t _Size> |
| 416 | inline _LIBCPP_INLINE_VISIBILITY |
| 417 | _LIBCPP_CONSTEXPR_AFTER_CXX17 bool |
| 418 | operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) |
| 419 | { |
| 420 | return __y < __x; |
| 421 | } |
| 422 | |
| 423 | template <class _Tp, size_t _Size> |
| 424 | inline _LIBCPP_INLINE_VISIBILITY |
| 425 | _LIBCPP_CONSTEXPR_AFTER_CXX17 bool |
| 426 | operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) |
| 427 | { |
| 428 | return !(__y < __x); |
| 429 | } |
| 430 | |
| 431 | template <class _Tp, size_t _Size> |
| 432 | inline _LIBCPP_INLINE_VISIBILITY |
| 433 | _LIBCPP_CONSTEXPR_AFTER_CXX17 bool |
| 434 | operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) |
| 435 | { |
| 436 | return !(__x < __y); |
| 437 | } |
| 438 | |
| 439 | template <class _Tp, size_t _Size> |
| 440 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 441 | __enable_if_t<_Size == 0 || __is_swappable<_Tp>::value, void> |
| 442 | swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y) |
| 443 | _NOEXCEPT_(noexcept(__x.swap(__y))) |
| 444 | { |
| 445 | __x.swap(__y); |
| 446 | } |
| 447 | |
| 448 | template <class _Tp, size_t _Size> |
| 449 | struct _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> > |
| 450 | : public integral_constant<size_t, _Size> {}; |
| 451 | |
| 452 | template <size_t _Ip, class _Tp, size_t _Size> |
| 453 | struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> > |
| 454 | { |
| 455 | static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)" ); |
| 456 | typedef _Tp type; |
| 457 | }; |
| 458 | |
| 459 | template <size_t _Ip, class _Tp, size_t _Size> |
| 460 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 461 | _Tp& |
| 462 | get(array<_Tp, _Size>& __a) _NOEXCEPT |
| 463 | { |
| 464 | static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)" ); |
| 465 | return __a.__elems_[_Ip]; |
| 466 | } |
| 467 | |
| 468 | template <size_t _Ip, class _Tp, size_t _Size> |
| 469 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 470 | const _Tp& |
| 471 | get(const array<_Tp, _Size>& __a) _NOEXCEPT |
| 472 | { |
| 473 | static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)" ); |
| 474 | return __a.__elems_[_Ip]; |
| 475 | } |
| 476 | |
| 477 | template <size_t _Ip, class _Tp, size_t _Size> |
| 478 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 479 | _Tp&& |
| 480 | get(array<_Tp, _Size>&& __a) _NOEXCEPT |
| 481 | { |
| 482 | static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)" ); |
| 483 | return _VSTD::move(__a.__elems_[_Ip]); |
| 484 | } |
| 485 | |
| 486 | template <size_t _Ip, class _Tp, size_t _Size> |
| 487 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 488 | const _Tp&& |
| 489 | get(const array<_Tp, _Size>&& __a) _NOEXCEPT |
| 490 | { |
| 491 | static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)" ); |
| 492 | return _VSTD::move(__a.__elems_[_Ip]); |
| 493 | } |
| 494 | |
| 495 | #if _LIBCPP_STD_VER > 17 |
| 496 | |
| 497 | template <typename _Tp, size_t _Size, size_t... _Index> |
| 498 | _LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size> |
| 499 | __to_array_lvalue_impl(_Tp (&__arr)[_Size], index_sequence<_Index...>) { |
| 500 | return {{__arr[_Index]...}}; |
| 501 | } |
| 502 | |
| 503 | template <typename _Tp, size_t _Size, size_t... _Index> |
| 504 | _LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size> |
| 505 | __to_array_rvalue_impl(_Tp(&&__arr)[_Size], index_sequence<_Index...>) { |
| 506 | return {{_VSTD::move(__arr[_Index])...}}; |
| 507 | } |
| 508 | |
| 509 | template <typename _Tp, size_t _Size> |
| 510 | _LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size> |
| 511 | to_array(_Tp (&__arr)[_Size]) noexcept(is_nothrow_constructible_v<_Tp, _Tp&>) { |
| 512 | static_assert( |
| 513 | !is_array_v<_Tp>, |
| 514 | "[array.creation]/1: to_array does not accept multidimensional arrays." ); |
| 515 | static_assert( |
| 516 | is_constructible_v<_Tp, _Tp&>, |
| 517 | "[array.creation]/1: to_array requires copy constructible elements." ); |
| 518 | return _VSTD::__to_array_lvalue_impl(__arr, make_index_sequence<_Size>()); |
| 519 | } |
| 520 | |
| 521 | template <typename _Tp, size_t _Size> |
| 522 | _LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size> |
| 523 | to_array(_Tp(&&__arr)[_Size]) noexcept(is_nothrow_move_constructible_v<_Tp>) { |
| 524 | static_assert( |
| 525 | !is_array_v<_Tp>, |
| 526 | "[array.creation]/4: to_array does not accept multidimensional arrays." ); |
| 527 | static_assert( |
| 528 | is_move_constructible_v<_Tp>, |
| 529 | "[array.creation]/4: to_array requires move constructible elements." ); |
| 530 | return _VSTD::__to_array_rvalue_impl(_VSTD::move(__arr), |
| 531 | make_index_sequence<_Size>()); |
| 532 | } |
| 533 | |
| 534 | #endif // _LIBCPP_STD_VER > 17 |
| 535 | |
| 536 | _LIBCPP_END_NAMESPACE_STD |
| 537 | |
| 538 | #endif // _LIBCPP_ARRAY |
| 539 | |