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