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