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,
size_t _Nm>
55 using _Type = _Tp[_Nm];
56 using _Is_swappable = __is_swappable<_Tp>;
57 using _Is_nothrow_swappable = __is_nothrow_swappable<_Tp>;
60 template<
typename _Tp>
61 struct __array_traits<_Tp, 0>
67 __attribute__((__always_inline__,__noreturn__))
68 _Tp& operator[](
size_t)
const noexcept { __builtin_trap(); }
71 __attribute__((__always_inline__))
72 operator _Tp*()
const noexcept {
return nullptr; }
93 template<
typename _Tp, std::
size_t _Nm>
96 typedef _Tp value_type;
97 typedef value_type* pointer;
98 typedef const value_type* const_pointer;
99 typedef value_type& reference;
100 typedef const value_type& const_reference;
101 typedef value_type* iterator;
102 typedef const value_type* const_iterator;
103 typedef std::size_t size_type;
104 typedef std::ptrdiff_t difference_type;
109 typename __array_traits<_Tp, _Nm>::_Type _M_elems;
114 _GLIBCXX20_CONSTEXPR
void
115 fill(
const value_type& __u)
116 { std::fill_n(begin(), size(), __u); }
118 _GLIBCXX20_CONSTEXPR
void
120 noexcept(__array_traits<_Tp, _Nm>::_Is_nothrow_swappable::value)
121 { std::swap_ranges(begin(), end(), __other.begin()); }
124 [[__gnu__::__const__, __nodiscard__]]
125 _GLIBCXX17_CONSTEXPR iterator
127 {
return iterator(data()); }
130 _GLIBCXX17_CONSTEXPR const_iterator
131 begin()
const noexcept
132 {
return const_iterator(data()); }
134 [[__gnu__::__const__, __nodiscard__]]
135 _GLIBCXX17_CONSTEXPR iterator
137 {
return iterator(data() + _Nm); }
140 _GLIBCXX17_CONSTEXPR const_iterator
142 {
return const_iterator(data() + _Nm); }
144 [[__gnu__::__const__, __nodiscard__]]
151 rbegin()
const noexcept
154 [[__gnu__::__const__, __nodiscard__]]
161 rend()
const noexcept
165 _GLIBCXX17_CONSTEXPR const_iterator
166 cbegin()
const noexcept
167 {
return const_iterator(data()); }
170 _GLIBCXX17_CONSTEXPR const_iterator
171 cend()
const noexcept
172 {
return const_iterator(data() + _Nm); }
176 crbegin()
const noexcept
181 crend()
const noexcept
185 [[__nodiscard__, __gnu__::__const__, __gnu__::__always_inline__]]
187 size()
const noexcept {
return _Nm; }
189 [[__nodiscard__, __gnu__::__const__, __gnu__::__always_inline__]]
191 max_size()
const noexcept {
return _Nm; }
193 [[__nodiscard__, __gnu__::__const__, __gnu__::__always_inline__]]
195 empty()
const noexcept {
return size() == 0; }
199 _GLIBCXX17_CONSTEXPR reference
200 operator[](size_type __n)
noexcept
202 __glibcxx_requires_subscript(__n);
203 return _M_elems[__n];
207 constexpr const_reference
208 operator[](size_type __n)
const noexcept
210#if __cplusplus >= 201402L
211 __glibcxx_requires_subscript(__n);
213 return _M_elems[__n];
216 _GLIBCXX17_CONSTEXPR reference
220 std::__throw_out_of_range_fmt(__N(
"array::at: __n (which is %zu) "
221 ">= _Nm (which is %zu)"),
223 return _M_elems[__n];
226 constexpr const_reference
227 at(size_type __n)
const
231 return __n < _Nm ? _M_elems[__n]
232 : (std::__throw_out_of_range_fmt(__N(
"array::at: __n (which is %zu) "
233 ">= _Nm (which is %zu)"),
239 _GLIBCXX17_CONSTEXPR reference
242 __glibcxx_requires_nonempty();
247 constexpr const_reference
248 front()
const noexcept
250#if __cplusplus >= 201402L
251 __glibcxx_requires_nonempty();
257 _GLIBCXX17_CONSTEXPR reference
260 __glibcxx_requires_nonempty();
261 return _M_elems[_Nm - 1];
265 constexpr const_reference
266 back()
const noexcept
268#if __cplusplus >= 201402L
269 __glibcxx_requires_nonempty();
271 return _M_elems[_Nm - 1];
274 [[__nodiscard__, __gnu__::__const__, __gnu__::__always_inline__]]
275 _GLIBCXX17_CONSTEXPR pointer
280 _GLIBCXX17_CONSTEXPR const_pointer
281 data()
const noexcept
285#if __cpp_deduction_guides >= 201606
286 template<
typename _Tp,
typename... _Up>
293 template<
typename _Tp, std::
size_t _Nm>
298 {
return std::equal(__one.begin(), __one.end(), __two.begin()); }
300#if __cpp_lib_three_way_comparison && __cpp_lib_concepts
301 template<
typename _Tp,
size_t _Nm>
303 constexpr __detail::__synth3way_t<_Tp>
304 operator<=>(
const array<_Tp, _Nm>& __a,
const array<_Tp, _Nm>& __b)
306 if constexpr (_Nm && __is_memcmp_ordered<_Tp>::__value)
307 if (!std::__is_constant_evaluated())
309 constexpr size_t __n = _Nm *
sizeof(_Tp);
310 return __builtin_memcmp(__a.data(), __b.data(), __n) <=> 0;
313 for (
size_t __i = 0; __i < _Nm; ++__i)
315 auto __c = __detail::__synth3way(__a[__i], __b[__i]);
319 return strong_ordering::equal;
322 template<
typename _Tp, std::
size_t _Nm>
326 operator!=(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
327 {
return !(__one == __two); }
329 template<
typename _Tp, std::
size_t _Nm>
333 operator<(
const array<_Tp, _Nm>& __a,
const array<_Tp, _Nm>& __b)
335 return std::lexicographical_compare(__a.begin(), __a.end(),
336 __b.begin(), __b.end());
339 template<
typename _Tp, std::
size_t _Nm>
343 operator>(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
344 {
return __two < __one; }
346 template<
typename _Tp, std::
size_t _Nm>
350 operator<=(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
351 {
return !(__one > __two); }
353 template<
typename _Tp, std::
size_t _Nm>
357 operator>=(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
358 {
return !(__one < __two); }
362 template<
typename _Tp, std::
size_t _Nm>
365#if __cplusplus > 201402L || !defined(__STRICT_ANSI__)
367 __enable_if_t<__array_traits<_Tp, _Nm>::_Is_swappable::value>
371 swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
372 noexcept(
noexcept(__one.swap(__two)))
373 { __one.swap(__two); }
375#if __cplusplus > 201402L || !defined(__STRICT_ANSI__)
376 template<
typename _Tp, std::
size_t _Nm>
377 __enable_if_t<!__array_traits<_Tp, _Nm>::_Is_swappable::value>
378 swap(array<_Tp, _Nm>&, array<_Tp, _Nm>&) =
delete;
381 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
384 get(array<_Tp, _Nm>& __arr)
noexcept
386 static_assert(_Int < _Nm,
"array index is within bounds");
387 return __arr._M_elems[_Int];
390 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
393 get(array<_Tp, _Nm>&& __arr)
noexcept
395 static_assert(_Int < _Nm,
"array index is within bounds");
399 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
402 get(
const array<_Tp, _Nm>& __arr)
noexcept
404 static_assert(_Int < _Nm,
"array index is within bounds");
405 return __arr._M_elems[_Int];
408 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
410 constexpr const _Tp&&
411 get(
const array<_Tp, _Nm>&& __arr)
noexcept
413 static_assert(_Int < _Nm,
"array index is within bounds");
417#if __cplusplus > 201703L
418#define __cpp_lib_to_array 201907L
420 template<
bool _Move =
false,
typename _Tp,
size_t... _Idx>
421 constexpr array<remove_cv_t<_Tp>,
sizeof...(_Idx)>
422 __to_array(_Tp (&__a)[
sizeof...(_Idx)], index_sequence<_Idx...>)
427 return {{__a[_Idx]...}};
430 template<
typename _Tp,
size_t _Nm>
432 constexpr array<remove_cv_t<_Tp>, _Nm>
433 to_array(_Tp (&__a)[_Nm])
434 noexcept(is_nothrow_constructible_v<_Tp, _Tp&>)
436 static_assert(!is_array_v<_Tp>);
437 static_assert(is_constructible_v<_Tp, _Tp&>);
438 if constexpr (is_constructible_v<_Tp, _Tp&>)
439 return __to_array(__a, make_index_sequence<_Nm>{});
440 __builtin_unreachable();
443 template<
typename _Tp,
size_t _Nm>
445 constexpr array<remove_cv_t<_Tp>, _Nm>
446 to_array(_Tp (&&__a)[_Nm])
447 noexcept(is_nothrow_move_constructible_v<_Tp>)
449 static_assert(!is_array_v<_Tp>);
450 static_assert(is_move_constructible_v<_Tp>);
451 if constexpr (is_move_constructible_v<_Tp>)
452 return __to_array<1>(__a, make_index_sequence<_Nm>{});
453 __builtin_unreachable();
460 template<
typename _Tp,
size_t _Nm>
465 template<
size_t _Ind,
typename _Tp,
size_t _Nm>
468 static_assert(_Ind < _Nm,
"array index is in range");
472#if __cplusplus >= 201703L
473 template<
typename _Tp,
size_t _Nm>
474 inline constexpr size_t tuple_size_v<array<_Tp, _Nm>> = _Nm;
476 template<
typename _Tp,
size_t _Nm>
477 inline constexpr size_t tuple_size_v<const array<_Tp, _Nm>> = _Nm;
480 template<
typename _Tp,
size_t _Nm>
484_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.
ISO C++ entities toplevel namespace is std.
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.