29 #ifndef _GLIBCXX_ARRAY 30 #define _GLIBCXX_ARRAY 1 32 #ifdef _GLIBCXX_SYSHDR 33 #pragma GCC system_header 36 #if __cplusplus < 201103L 50 #define __glibcxx_want_array_constexpr 51 #define __glibcxx_want_freestanding_array 52 #define __glibcxx_want_nonmember_container_access 53 #define __glibcxx_want_to_array 56 namespace std _GLIBCXX_VISIBILITY(default)
58 _GLIBCXX_BEGIN_NAMESPACE_VERSION
60 template<
typename _Tp,
size_t _Nm>
63 using _Type = _Tp[_Nm];
64 using _Is_swappable = __is_swappable<_Tp>;
65 using _Is_nothrow_swappable = __is_nothrow_swappable<_Tp>;
68 template<
typename _Tp>
69 struct __array_traits<_Tp, 0>
75 __attribute__((__always_inline__,__noreturn__))
76 _Tp& operator[](
size_t)
const noexcept { __builtin_trap(); }
79 __attribute__((__always_inline__))
80 constexpr
explicit operator _Tp*()
const noexcept {
return nullptr; }
101 template<
typename _Tp, std::
size_t _Nm>
104 typedef _Tp value_type;
105 typedef value_type* pointer;
106 typedef const value_type* const_pointer;
107 typedef value_type& reference;
108 typedef const value_type& const_reference;
109 typedef value_type* iterator;
110 typedef const value_type* const_iterator;
111 typedef std::size_t size_type;
112 typedef std::ptrdiff_t difference_type;
117 typename __array_traits<_Tp, _Nm>::_Type _M_elems;
122 _GLIBCXX20_CONSTEXPR
void 123 fill(
const value_type& __u)
126 _GLIBCXX20_CONSTEXPR
void 128 noexcept(__array_traits<_Tp, _Nm>::_Is_nothrow_swappable::value)
132 [[__gnu__::__const__, __nodiscard__]]
133 _GLIBCXX17_CONSTEXPR iterator
135 {
return iterator(
data()); }
138 _GLIBCXX17_CONSTEXPR const_iterator
139 begin()
const noexcept
140 {
return const_iterator(
data()); }
142 [[__gnu__::__const__, __nodiscard__]]
143 _GLIBCXX17_CONSTEXPR iterator
145 {
return iterator(
data() + _Nm); }
148 _GLIBCXX17_CONSTEXPR const_iterator
150 {
return const_iterator(
data() + _Nm); }
152 [[__gnu__::__const__, __nodiscard__]]
153 _GLIBCXX17_CONSTEXPR reverse_iterator
155 {
return reverse_iterator(
end()); }
158 _GLIBCXX17_CONSTEXPR const_reverse_iterator
160 {
return const_reverse_iterator(
end()); }
162 [[__gnu__::__const__, __nodiscard__]]
163 _GLIBCXX17_CONSTEXPR reverse_iterator
165 {
return reverse_iterator(
begin()); }
168 _GLIBCXX17_CONSTEXPR const_reverse_iterator
169 rend()
const noexcept
170 {
return const_reverse_iterator(
begin()); }
173 _GLIBCXX17_CONSTEXPR const_iterator
175 {
return const_iterator(
data()); }
178 _GLIBCXX17_CONSTEXPR const_iterator
179 cend()
const noexcept
180 {
return const_iterator(
data() + _Nm); }
183 _GLIBCXX17_CONSTEXPR const_reverse_iterator
185 {
return const_reverse_iterator(
end()); }
188 _GLIBCXX17_CONSTEXPR const_reverse_iterator
189 crend()
const noexcept
190 {
return const_reverse_iterator(
begin()); }
193 [[__nodiscard__, __gnu__::__const__, __gnu__::__always_inline__]]
195 size()
const noexcept {
return _Nm; }
197 [[__nodiscard__, __gnu__::__const__, __gnu__::__always_inline__]]
199 max_size()
const noexcept {
return _Nm; }
201 [[__nodiscard__, __gnu__::__const__, __gnu__::__always_inline__]]
203 empty()
const noexcept {
return size() == 0; }
207 _GLIBCXX17_CONSTEXPR reference
208 operator[](size_type __n) noexcept
210 __glibcxx_requires_subscript(__n);
211 return _M_elems[__n];
215 constexpr const_reference
216 operator[](size_type __n)
const noexcept
218 #if __cplusplus >= 201402L 219 __glibcxx_requires_subscript(__n);
221 return _M_elems[__n];
224 _GLIBCXX17_CONSTEXPR reference
228 std::__throw_out_of_range_fmt(__N(
"array::at: __n (which is %zu) " 229 ">= _Nm (which is %zu)"),
231 return _M_elems[__n];
234 constexpr const_reference
235 at(size_type __n)
const 239 return __n < _Nm ? _M_elems[__n]
240 : (std::__throw_out_of_range_fmt(__N(
"array::at: __n (which is %zu) " 241 ">= _Nm (which is %zu)"),
247 _GLIBCXX17_CONSTEXPR reference
250 __glibcxx_requires_nonempty();
251 return _M_elems[(size_type)0];
255 constexpr const_reference
256 front()
const noexcept
258 #if __cplusplus >= 201402L 259 __glibcxx_requires_nonempty();
261 return _M_elems[(size_type)0];
265 _GLIBCXX17_CONSTEXPR reference
268 __glibcxx_requires_nonempty();
269 return _M_elems[_Nm - 1];
273 constexpr const_reference
274 back()
const noexcept
276 #if __cplusplus >= 201402L 277 __glibcxx_requires_nonempty();
279 return _M_elems[_Nm - 1];
282 [[__nodiscard__, __gnu__::__const__, __gnu__::__always_inline__]]
283 _GLIBCXX17_CONSTEXPR pointer
285 {
return static_cast<pointer
>(_M_elems); }
288 _GLIBCXX17_CONSTEXPR const_pointer
289 data()
const noexcept
290 {
return static_cast<const_pointer
>(_M_elems); }
293 #if __cpp_deduction_guides >= 201606 294 template<
typename _Tp,
typename... _Up>
301 template<
typename _Tp, std::
size_t _Nm>
306 {
return std::__equal_aux1(__one.begin(), __one.end(), __two.begin()); }
308 #if __cpp_lib_three_way_comparison // C++ >= 20 && lib_concepts 309 template<
typename _Tp,
size_t _Nm>
311 constexpr __detail::__synth3way_t<_Tp>
314 if constexpr (_Nm && __is_memcmp_ordered<_Tp>::__value)
315 if (!std::__is_constant_evaluated())
317 constexpr
size_t __n = _Nm *
sizeof(_Tp);
318 return __builtin_memcmp(__a.data(), __b.data(), __n) <=> 0;
321 for (
size_t __i = 0; __i < _Nm; ++__i)
323 auto __c = __detail::__synth3way(__a[__i], __b[__i]);
327 return strong_ordering::equal;
330 template<
typename _Tp, std::
size_t _Nm>
335 {
return !(__one == __two); }
337 template<
typename _Tp, std::
size_t _Nm>
344 __b.begin(), __b.end());
347 template<
typename _Tp, std::
size_t _Nm>
352 {
return __two < __one; }
354 template<
typename _Tp, std::
size_t _Nm>
359 {
return !(__one > __two); }
361 template<
typename _Tp, std::
size_t _Nm>
366 {
return !(__one < __two); }
367 #endif // three_way_comparison && concepts 370 template<
typename _Tp, std::
size_t _Nm>
373 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11 375 __enable_if_t<__array_traits<_Tp, _Nm>::_Is_swappable::value>
380 noexcept(noexcept(__one.swap(__two)))
381 { __one.swap(__two); }
383 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11 386 template<
typename _Tp, std::
size_t _Nm>
387 __enable_if_t<!__array_traits<_Tp, _Nm>::_Is_swappable::value>
391 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
396 static_assert(_Int < _Nm,
"array index is within bounds");
397 return __arr._M_elems[_Int];
400 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
405 static_assert(_Int < _Nm,
"array index is within bounds");
409 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
414 static_assert(_Int < _Nm,
"array index is within bounds");
415 return __arr._M_elems[_Int];
418 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
420 constexpr
const _Tp&&
423 static_assert(_Int < _Nm,
"array index is within bounds");
427 #ifdef __cpp_lib_to_array // C++ >= 20 && __cpp_generic_lambdas >= 201707L 428 template<
typename _Tp,
size_t _Nm>
432 noexcept(is_nothrow_constructible_v<_Tp, _Tp&>)
434 static_assert(!is_array_v<_Tp>);
435 static_assert(is_constructible_v<_Tp, _Tp&>);
436 if constexpr (is_constructible_v<_Tp, _Tp&>)
438 if constexpr (is_trivially_copyable_v<_Tp>
439 && is_trivially_default_constructible_v<_Tp>
440 && is_copy_assignable_v<_Tp>)
442 array<remove_cv_t<_Tp>, _Nm> __arr;
443 if (!__is_constant_evaluated() && _Nm != 0)
444 __builtin_memcpy((
void*)__arr.data(), (
void*)__a,
sizeof(__a));
446 for (
size_t __i = 0; __i < _Nm; ++__i)
447 __arr._M_elems[__i] = __a[__i];
452 return array<remove_cv_t<_Tp>, _Nm>{{ __a[_Idx]... }};
456 __builtin_unreachable();
459 template<
typename _Tp,
size_t _Nm>
461 constexpr array<remove_cv_t<_Tp>, _Nm>
463 noexcept(is_nothrow_move_constructible_v<_Tp>)
465 static_assert(!is_array_v<_Tp>);
466 static_assert(is_move_constructible_v<_Tp>);
467 if constexpr (is_move_constructible_v<_Tp>)
469 if constexpr (is_trivially_copyable_v<_Tp>
470 && is_trivially_default_constructible_v<_Tp>
471 && is_copy_assignable_v<_Tp>)
473 array<remove_cv_t<_Tp>, _Nm> __arr;
474 if (!__is_constant_evaluated() && _Nm != 0)
475 __builtin_memcpy((
void*)__arr.data(), (
void*)__a,
sizeof(__a));
477 for (
size_t __i = 0; __i < _Nm; ++__i)
478 __arr._M_elems[__i] = __a[__i];
483 return array<remove_cv_t<_Tp>, _Nm>{{
std::move(__a[_Idx])... }};
487 __builtin_unreachable();
489 #endif // __cpp_lib_to_array 494 template<
typename _Tp,
size_t _Nm>
499 template<
size_t _Ind,
typename _Tp,
size_t _Nm>
502 static_assert(_Ind < _Nm,
"array index is in range");
506 #if __cplusplus >= 201703L 507 template<
typename _Tp,
size_t _Nm>
508 inline constexpr
size_t tuple_size_v<array<_Tp, _Nm>> = _Nm;
510 template<
typename _Tp,
size_t _Nm>
511 inline constexpr
size_t tuple_size_v<const array<_Tp, _Nm>> = _Nm;
514 template<
typename _Tp,
size_t _Nm>
515 struct __is_tuple_like_impl<array<_Tp, _Nm>> :
true_type 518 _GLIBCXX_END_NAMESPACE_VERSION
523 #endif // _GLIBCXX_ARRAY constexpr auto data(_Container &__cont) noexcept(noexcept(__cont.data())) -> decltype(__cont.data())
Return the data pointer of a container.
make_integer_sequence< size_t, _Num > make_index_sequence
Alias template make_index_sequence.
Class template integer_sequence.
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
__bool_constant< true > true_type
The type used as a compile-time boolean with true value.
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.
constexpr _OI fill_n(_OI __first, _Size __n, const _Tp &__value)
Fills the range [first,first+n) with copies of value.
Gives the type of the ith element of a given tuple type.
constexpr auto empty(const _Container &__cont) noexcept(noexcept(__cont.empty())) -> decltype(__cont.empty())
Return whether a container is empty.
ISO C++ entities toplevel namespace is std.
constexpr auto cbegin(const _Container &__cont) noexcept(noexcept(std::begin(__cont))) -> decltype(std::begin(__cont))
Return an iterator pointing to the first element of the const container.
_Tp * end(valarray< _Tp > &__va) noexcept
Return an iterator pointing to one past the last element of the valarray.
constexpr auto crbegin(const _Container &__cont) noexcept(noexcept(std::rbegin(__cont))) -> decltype(std::rbegin(__cont))
Return a reverse iterator pointing to the last element of the const container.
constexpr bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
Finds the size of a given tuple type.
constexpr auto cend(const _Container &__cont) noexcept(noexcept(std::end(__cont))) -> decltype(std::end(__cont))
Return an iterator pointing to one past the last element of the const container.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
A standard container for storing a fixed size sequence of elements.
constexpr auto crend(const _Container &__cont) noexcept(noexcept(std::rend(__cont))) -> decltype(std::rend(__cont))
Return a reverse iterator pointing one past the first element of the const container.
constexpr auto rend(_Container &__cont) noexcept(noexcept(__cont.rend())) -> decltype(__cont.rend())
Return a reverse iterator pointing one past the first element of the container.
constexpr auto rbegin(_Container &__cont) noexcept(noexcept(__cont.rbegin())) -> decltype(__cont.rbegin())
Return a reverse iterator pointing to the last element of the container.
constexpr _ForwardIterator2 swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
Swap the elements of two sequences.
_Tp * begin(valarray< _Tp > &__va) noexcept
Return an iterator pointing to the first element of the valarray.