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