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