30#define _GLIBCXX_ARRAY 1
32#pragma GCC system_header
34#if __cplusplus < 201103L
48namespace std _GLIBCXX_VISIBILITY(default)
50_GLIBCXX_BEGIN_NAMESPACE_VERSION
52 template<
typename _Tp, std::
size_t _Nm>
55 typedef _Tp _Type[_Nm];
56 typedef __is_swappable<_Tp> _Is_swappable;
57 typedef __is_nothrow_swappable<_Tp> _Is_nothrow_swappable;
60 _S_ref(
const _Type& __t, std::size_t __n)
noexcept
61 {
return const_cast<_Tp&
>(__t[__n]); }
64 _S_ptr(
const _Type& __t)
noexcept
65 {
return const_cast<_Tp*
>(__t); }
68 template<
typename _Tp>
69 struct __array_traits<_Tp, 0>
76 _S_ref(
const _Type&, std::size_t)
noexcept
77 {
return *
static_cast<_Tp*
>(
nullptr); }
80 _S_ptr(
const _Type&)
noexcept
98 template<
typename _Tp, std::
size_t _Nm>
101 typedef _Tp value_type;
102 typedef value_type* pointer;
103 typedef const value_type* const_pointer;
104 typedef value_type& reference;
105 typedef const value_type& const_reference;
106 typedef value_type* iterator;
107 typedef const value_type* const_iterator;
108 typedef std::size_t size_type;
109 typedef std::ptrdiff_t difference_type;
114 typedef __array_traits<_Tp, _Nm> _AT_Type;
115 typename _AT_Type::_Type _M_elems;
120 _GLIBCXX20_CONSTEXPR
void
121 fill(
const value_type& __u)
122 { std::fill_n(begin(), size(), __u); }
124 _GLIBCXX20_CONSTEXPR
void
126 noexcept(_AT_Type::_Is_nothrow_swappable::value)
127 { std::swap_ranges(begin(), end(), __other.begin()); }
130 [[__gnu__::__const__, __nodiscard__]]
131 _GLIBCXX17_CONSTEXPR iterator
133 {
return iterator(data()); }
136 _GLIBCXX17_CONSTEXPR const_iterator
137 begin()
const noexcept
138 {
return const_iterator(data()); }
140 [[__gnu__::__const__, __nodiscard__]]
141 _GLIBCXX17_CONSTEXPR iterator
143 {
return iterator(data() + _Nm); }
146 _GLIBCXX17_CONSTEXPR const_iterator
148 {
return const_iterator(data() + _Nm); }
150 [[__gnu__::__const__, __nodiscard__]]
157 rbegin()
const noexcept
160 [[__gnu__::__const__, __nodiscard__]]
167 rend()
const noexcept
171 _GLIBCXX17_CONSTEXPR const_iterator
172 cbegin()
const noexcept
173 {
return const_iterator(data()); }
176 _GLIBCXX17_CONSTEXPR const_iterator
177 cend()
const noexcept
178 {
return const_iterator(data() + _Nm); }
182 crbegin()
const noexcept
187 crend()
const noexcept
191 [[__gnu__::__const__, __nodiscard__]]
193 size()
const noexcept {
return _Nm; }
195 [[__gnu__::__const__, __nodiscard__]]
197 max_size()
const noexcept {
return _Nm; }
199 [[__gnu__::__const__, __nodiscard__]]
201 empty()
const noexcept {
return size() == 0; }
205 _GLIBCXX17_CONSTEXPR reference
206 operator[](size_type __n)
noexcept
208 __glibcxx_requires_subscript(__n);
209 return _AT_Type::_S_ref(_M_elems, __n);
213 constexpr const_reference
214 operator[](size_type __n)
const noexcept
216#if __cplusplus >= 201402L
217 __glibcxx_requires_subscript(__n);
219 return _AT_Type::_S_ref(_M_elems, __n);
222 _GLIBCXX17_CONSTEXPR reference
226 std::__throw_out_of_range_fmt(__N(
"array::at: __n (which is %zu) "
227 ">= _Nm (which is %zu)"),
229 return _AT_Type::_S_ref(_M_elems, __n);
232 constexpr const_reference
233 at(size_type __n)
const
237 return __n < _Nm ? _AT_Type::_S_ref(_M_elems, __n)
238 : (std::__throw_out_of_range_fmt(__N(
"array::at: __n (which is %zu) "
239 ">= _Nm (which is %zu)"),
241 _AT_Type::_S_ref(_M_elems, 0));
245 _GLIBCXX17_CONSTEXPR reference
248 __glibcxx_requires_nonempty();
253 constexpr const_reference
254 front()
const noexcept
256#if __cplusplus >= 201402L
257 __glibcxx_requires_nonempty();
259 return _AT_Type::_S_ref(_M_elems, 0);
263 _GLIBCXX17_CONSTEXPR reference
266 __glibcxx_requires_nonempty();
267 return _Nm ? *(end() - 1) : *end();
271 constexpr const_reference
272 back()
const noexcept
274#if __cplusplus >= 201402L
275 __glibcxx_requires_nonempty();
277 return _Nm ? _AT_Type::_S_ref(_M_elems, _Nm - 1)
278 : _AT_Type::_S_ref(_M_elems, 0);
281 [[__gnu__::__const__, __nodiscard__]]
282 _GLIBCXX17_CONSTEXPR pointer
284 {
return _AT_Type::_S_ptr(_M_elems); }
287 _GLIBCXX17_CONSTEXPR const_pointer
288 data()
const noexcept
289 {
return _AT_Type::_S_ptr(_M_elems); }
292#if __cpp_deduction_guides >= 201606
293 template<
typename _Tp,
typename... _Up>
300 template<
typename _Tp, std::
size_t _Nm>
305 {
return std::equal(__one.begin(), __one.end(), __two.begin()); }
307#if __cpp_lib_three_way_comparison && __cpp_lib_concepts
308 template<
typename _Tp,
size_t _Nm>
310 constexpr __detail::__synth3way_t<_Tp>
311 operator<=>(
const array<_Tp, _Nm>& __a,
const array<_Tp, _Nm>& __b)
313 if constexpr (_Nm && __is_memcmp_ordered<_Tp>::__value)
314 if (!std::__is_constant_evaluated())
316 constexpr size_t __n = _Nm *
sizeof(_Tp);
317 return __builtin_memcmp(__a.data(), __b.data(), __n) <=> 0;
320 for (
size_t __i = 0; __i < _Nm; ++__i)
322 auto __c = __detail::__synth3way(__a[__i], __b[__i]);
326 return strong_ordering::equal;
329 template<
typename _Tp, std::
size_t _Nm>
333 operator!=(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
334 {
return !(__one == __two); }
336 template<
typename _Tp, std::
size_t _Nm>
340 operator<(
const array<_Tp, _Nm>& __a,
const array<_Tp, _Nm>& __b)
342 return std::lexicographical_compare(__a.begin(), __a.end(),
343 __b.begin(), __b.end());
346 template<
typename _Tp, std::
size_t _Nm>
350 operator>(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
351 {
return __two < __one; }
353 template<
typename _Tp, std::
size_t _Nm>
357 operator<=(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
358 {
return !(__one > __two); }
360 template<
typename _Tp, std::
size_t _Nm>
364 operator>=(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
365 {
return !(__one < __two); }
369 template<
typename _Tp, std::
size_t _Nm>
372#if __cplusplus > 201402L || !defined(__STRICT_ANSI__)
375 __array_traits<_Tp, _Nm>::_Is_swappable::value
380 swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
381 noexcept(
noexcept(__one.swap(__two)))
382 { __one.swap(__two); }
384#if __cplusplus > 201402L || !defined(__STRICT_ANSI__)
385 template<
typename _Tp, std::
size_t _Nm>
387 !__array_traits<_Tp, _Nm>::_Is_swappable::value>::type
388 swap(array<_Tp, _Nm>&, array<_Tp, _Nm>&) =
delete;
391 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
394 get(array<_Tp, _Nm>& __arr)
noexcept
396 static_assert(_Int < _Nm,
"array index is within bounds");
397 return __array_traits<_Tp, _Nm>::_S_ref(__arr._M_elems, _Int);
400 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
403 get(array<_Tp, _Nm>&& __arr)
noexcept
405 static_assert(_Int < _Nm,
"array index is within bounds");
409 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
412 get(
const array<_Tp, _Nm>& __arr)
noexcept
414 static_assert(_Int < _Nm,
"array index is within bounds");
415 return __array_traits<_Tp, _Nm>::_S_ref(__arr._M_elems, _Int);
418 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
420 constexpr const _Tp&&
421 get(
const array<_Tp, _Nm>&& __arr)
noexcept
423 static_assert(_Int < _Nm,
"array index is within bounds");
427#if __cplusplus >= 202002L && __cpp_generic_lambdas >= 201707L
428#define __cpp_lib_to_array 201907L
429 template<
typename _Tp,
size_t _Nm>
431 constexpr array<remove_cv_t<_Tp>, _Nm>
433 noexcept(is_nothrow_constructible_v<_Tp, _Tp&>)
435 static_assert(!is_array_v<_Tp>);
436 static_assert(is_constructible_v<_Tp, _Tp&>);
437 if constexpr (is_constructible_v<_Tp, _Tp&>)
439 if constexpr (is_trivial_v<_Tp>)
441 array<remove_cv_t<_Tp>, _Nm> __arr;
442 if (!__is_constant_evaluated() && _Nm != 0)
443 __builtin_memcpy((
void*)__arr.data(), (
void*)__a,
sizeof(__a));
445 for (
size_t __i = 0; __i < _Nm; ++__i)
446 __arr._M_elems[__i] = __a[__i];
451 return array<remove_cv_t<_Tp>, _Nm>{{ __a[_Idx]... }};
452 }(make_index_sequence<_Nm>{});
455 __builtin_unreachable();
458 template<
typename _Tp,
size_t _Nm>
460 constexpr array<remove_cv_t<_Tp>, _Nm>
462 noexcept(is_nothrow_move_constructible_v<_Tp>)
464 static_assert(!is_array_v<_Tp>);
465 static_assert(is_move_constructible_v<_Tp>);
466 if constexpr (is_move_constructible_v<_Tp>)
468 if constexpr (is_trivial_v<_Tp>)
470 array<remove_cv_t<_Tp>, _Nm> __arr;
471 if (!__is_constant_evaluated() && _Nm != 0)
472 __builtin_memcpy((
void*)__arr.data(), (
void*)__a,
sizeof(__a));
474 for (
size_t __i = 0; __i < _Nm; ++__i)
475 __arr._M_elems[__i] = __a[__i];
480 return array<remove_cv_t<_Tp>, _Nm>{{
std::move(__a[_Idx])... }};
481 }(make_index_sequence<_Nm>{});
484 __builtin_unreachable();
491 template<
typename _Tp,
size_t _Nm>
496 template<
size_t _Ind,
typename _Tp,
size_t _Nm>
499 static_assert(_Ind < _Nm,
"array index is in range");
503#if __cplusplus >= 201703L
504 template<
typename _Tp,
size_t _Nm>
505 inline constexpr size_t tuple_size_v<array<_Tp, _Nm>> = _Nm;
507 template<
typename _Tp,
size_t _Nm>
508 inline constexpr size_t tuple_size_v<const array<_Tp, _Nm>> = _Nm;
511 template<
typename _Tp,
size_t _Nm>
515_GLIBCXX_END_NAMESPACE_VERSION
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
typename enable_if< _Cond, _Tp >::type enable_if_t
Alias template for enable_if.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
void swap(any &__x, any &__y) noexcept
Exchange the states of two any objects.
constexpr array< remove_cv_t< _Tp >, _Nm > to_array(_Tp(&__a)[_Nm]) noexcept(is_nothrow_constructible< remove_cv_t< _Tp >, _Tp & >::value)
Create a std::array from an array.
ISO C++ entities toplevel namespace is std.
integer_sequence< size_t, _Idx... > index_sequence
Alias template index_sequence.
A standard container for storing a fixed size sequence of elements.
Finds the size of a given tuple type.
Gives the type of the ith element of a given tuple type.