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