29 #ifndef _GLIBCXX_ARRAY
30 #define _GLIBCXX_ARRAY 1
32 #pragma GCC system_header
34 #if __cplusplus < 201103L
43 namespace std _GLIBCXX_VISIBILITY(default)
45 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
47 template<
typename _Tp, std::
size_t _Nm>
50 typedef _Tp _Type[_Nm];
51 typedef __is_swappable<_Tp> _Is_swappable;
52 typedef __is_nothrow_swappable<_Tp> _Is_nothrow_swappable;
55 _S_ref(
const _Type& __t, std::size_t __n) noexcept
56 {
return const_cast<_Tp&
>(__t[__n]); }
59 _S_ptr(
const _Type& __t) noexcept
60 {
return const_cast<_Tp*
>(__t); }
63 template<
typename _Tp>
64 struct __array_traits<_Tp, 0>
71 _S_ref(
const _Type&, std::size_t) noexcept
72 {
return *
static_cast<_Tp*
>(
nullptr); }
75 _S_ptr(
const _Type&) noexcept
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 typedef _GLIBCXX_STD_C::__array_traits<_Tp, _Nm> _AT_Type;
110 typename _AT_Type::_Type _M_elems;
115 _GLIBCXX20_CONSTEXPR
void
116 fill(
const value_type& __u)
119 _GLIBCXX20_CONSTEXPR
void
121 noexcept(_AT_Type::_Is_nothrow_swappable::value)
125 _GLIBCXX17_CONSTEXPR iterator
127 {
return iterator(data()); }
129 _GLIBCXX17_CONSTEXPR const_iterator
130 begin()
const noexcept
131 {
return const_iterator(data()); }
133 _GLIBCXX17_CONSTEXPR iterator
135 {
return iterator(data() + _Nm); }
137 _GLIBCXX17_CONSTEXPR const_iterator
139 {
return const_iterator(data() + _Nm); }
146 rbegin()
const noexcept
154 rend()
const noexcept
157 _GLIBCXX17_CONSTEXPR const_iterator
158 cbegin()
const noexcept
159 {
return const_iterator(data()); }
161 _GLIBCXX17_CONSTEXPR const_iterator
162 cend()
const noexcept
163 {
return const_iterator(data() + _Nm); }
166 crbegin()
const noexcept
170 crend()
const noexcept
175 size()
const noexcept {
return _Nm; }
178 max_size()
const noexcept {
return _Nm; }
180 _GLIBCXX_NODISCARD constexpr
bool
181 empty()
const noexcept {
return size() == 0; }
184 _GLIBCXX17_CONSTEXPR reference
185 operator[](size_type __n) noexcept
186 {
return _AT_Type::_S_ref(_M_elems, __n); }
188 constexpr const_reference
189 operator[](size_type __n)
const noexcept
190 {
return _AT_Type::_S_ref(_M_elems, __n); }
192 _GLIBCXX17_CONSTEXPR reference
196 std::__throw_out_of_range_fmt(__N(
"array::at: __n (which is %zu) "
197 ">= _Nm (which is %zu)"),
199 return _AT_Type::_S_ref(_M_elems, __n);
202 constexpr const_reference
203 at(size_type __n)
const
207 return __n < _Nm ? _AT_Type::_S_ref(_M_elems, __n)
208 : (std::__throw_out_of_range_fmt(__N(
"array::at: __n (which is %zu) "
209 ">= _Nm (which is %zu)"),
211 _AT_Type::_S_ref(_M_elems, 0));
214 _GLIBCXX17_CONSTEXPR reference
218 constexpr const_reference
219 front()
const noexcept
220 {
return _AT_Type::_S_ref(_M_elems, 0); }
222 _GLIBCXX17_CONSTEXPR reference
224 {
return _Nm ? *(end() - 1) : *end(); }
226 constexpr const_reference
227 back()
const noexcept
229 return _Nm ? _AT_Type::_S_ref(_M_elems, _Nm - 1)
230 : _AT_Type::_S_ref(_M_elems, 0);
233 _GLIBCXX17_CONSTEXPR pointer
235 {
return _AT_Type::_S_ptr(_M_elems); }
237 _GLIBCXX17_CONSTEXPR const_pointer
238 data()
const noexcept
239 {
return _AT_Type::_S_ptr(_M_elems); }
242 #if __cpp_deduction_guides >= 201606
243 template<
typename _Tp,
typename... _Up>
250 template<
typename _Tp, std::
size_t _Nm>
254 {
return std::equal(__one.begin(), __one.end(), __two.begin()); }
256 #if __cpp_lib_three_way_comparison && __cpp_lib_concepts
257 template<
typename _Tp,
size_t _Nm>
258 constexpr __detail::__synth3way_t<_Tp>
259 operator<=>(
const array<_Tp, _Nm>& __a,
const array<_Tp, _Nm>& __b)
261 #ifdef __cpp_lib_is_constant_evaluated
262 if constexpr (_Nm && __is_memcmp_ordered<_Tp>::__value)
263 if (!std::is_constant_evaluated())
265 constexpr
size_t __n = _Nm *
sizeof(_Tp);
266 return __builtin_memcmp(__a.data(), __b.data(), __n) <=> 0;
270 for (
size_t __i = 0; __i < _Nm; ++__i)
272 auto __c = __detail::__synth3way(__a[__i], __b[__i]);
276 return strong_ordering::equal;
279 template<
typename _Tp, std::
size_t _Nm>
282 operator!=(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
283 {
return !(__one == __two); }
285 template<
typename _Tp, std::
size_t _Nm>
288 operator<(const array<_Tp, _Nm>& __a,
const array<_Tp, _Nm>& __b)
291 __b.begin(), __b.end());
294 template<
typename _Tp, std::
size_t _Nm>
297 operator>(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
298 {
return __two < __one; }
300 template<
typename _Tp, std::
size_t _Nm>
303 operator<=(const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
304 {
return !(__one > __two); }
306 template<
typename _Tp, std::
size_t _Nm>
309 operator>=(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
310 {
return !(__one < __two); }
311 #endif // three_way_comparison && concepts
314 template<
typename _Tp, std::
size_t _Nm>
317 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
320 _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>::_Is_swappable::value
325 swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
326 noexcept(noexcept(__one.swap(__two)))
327 { __one.swap(__two); }
329 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
330 template<
typename _Tp, std::
size_t _Nm>
332 !_GLIBCXX_STD_C::__array_traits<_Tp, _Nm>::_Is_swappable::value>::type
333 swap(array<_Tp, _Nm>&, array<_Tp, _Nm>&) =
delete;
336 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
338 get(array<_Tp, _Nm>& __arr) noexcept
340 static_assert(_Int < _Nm,
"array index is within bounds");
341 return _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>::
342 _S_ref(__arr._M_elems, _Int);
345 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
347 get(array<_Tp, _Nm>&& __arr) noexcept
349 static_assert(_Int < _Nm,
"array index is within bounds");
350 return std::move(_GLIBCXX_STD_C::get<_Int>(__arr));
353 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
355 get(
const array<_Tp, _Nm>& __arr) noexcept
357 static_assert(_Int < _Nm,
"array index is within bounds");
358 return _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>::
359 _S_ref(__arr._M_elems, _Int);
362 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
363 constexpr
const _Tp&&
364 get(
const array<_Tp, _Nm>&& __arr) noexcept
366 static_assert(_Int < _Nm,
"array index is within bounds");
367 return std::move(_GLIBCXX_STD_C::get<_Int>(__arr));
370 #if __cplusplus > 201703L
371 #define __cpp_lib_to_array 201907L
373 template<
bool _Move =
false,
typename _Tp,
size_t... _Idx>
374 constexpr array<remove_cv_t<_Tp>,
sizeof...(_Idx)>
375 __to_array(_Tp (&__a)[
sizeof...(_Idx)], index_sequence<_Idx...>)
380 return {{__a[_Idx]...}};
383 template<
typename _Tp,
size_t _Nm>
384 constexpr array<remove_cv_t<_Tp>, _Nm>
385 to_array(_Tp (&__a)[_Nm])
386 noexcept(is_nothrow_constructible_v<_Tp, _Tp&>)
388 static_assert(!is_array_v<_Tp>);
389 static_assert(is_constructible_v<_Tp, _Tp&>);
390 if constexpr (is_constructible_v<_Tp, _Tp&>)
392 __builtin_unreachable();
395 template<
typename _Tp,
size_t _Nm>
396 constexpr array<remove_cv_t<_Tp>, _Nm>
397 to_array(_Tp (&&__a)[_Nm])
398 noexcept(is_nothrow_move_constructible_v<_Tp>)
400 static_assert(!is_array_v<_Tp>);
401 static_assert(is_move_constructible_v<_Tp>);
402 if constexpr (is_move_constructible_v<_Tp>)
404 __builtin_unreachable();
408 _GLIBCXX_END_NAMESPACE_CONTAINER
411 namespace std _GLIBCXX_VISIBILITY(default)
413 _GLIBCXX_BEGIN_NAMESPACE_VERSION
418 template<
typename _Tp>
422 template<
typename _Tp, std::
size_t _Nm>
427 template<std::
size_t _Int,
typename _Tp>
431 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
434 static_assert(_Int < _Nm,
"index is out of bounds");
438 template<
typename _Tp, std::
size_t _Nm>
439 struct __is_tuple_like_impl<_GLIBCXX_STD_C::
array<_Tp, _Nm>> :
true_type
442 _GLIBCXX_END_NAMESPACE_VERSION
445 #ifdef _GLIBCXX_DEBUG
451 #endif // _GLIBCXX_ARRAY
make_integer_sequence< size_t, _Num > make_index_sequence
Alias template make_index_sequence.
constexpr bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
A standard container for storing a fixed size sequence of elements.
constexpr _OI fill_n(_OI __first, _Size __n, const _Tp &__value)
Fills the range [first,first+n) with copies of value.
constexpr bool equal(_IIter1 __first1, _IIter1 __last1, _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
Tests a range for element-wise equality.
constexpr _ForwardIterator2 swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
Swap the elements of two sequences.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.