29 #ifndef _GLIBCXX_ARRAY
30 #define _GLIBCXX_ARRAY 1
32 #pragma GCC system_header
34 #if __cplusplus < 201103L
44 namespace std _GLIBCXX_VISIBILITY(default)
46 _GLIBCXX_BEGIN_NAMESPACE_VERSION
48 template<
typename _Tp, std::
size_t _Nm>
51 typedef _Tp _Type[_Nm];
52 typedef __is_swappable<_Tp> _Is_swappable;
53 typedef __is_nothrow_swappable<_Tp> _Is_nothrow_swappable;
56 _S_ref(
const _Type& __t, std::size_t __n) noexcept
57 {
return const_cast<_Tp&
>(__t[__n]); }
60 _S_ptr(
const _Type& __t) noexcept
61 {
return const_cast<_Tp*
>(__t); }
64 template<
typename _Tp>
65 struct __array_traits<_Tp, 0>
72 _S_ref(
const _Type&, std::size_t) noexcept
73 {
return *
static_cast<_Tp*
>(
nullptr); }
76 _S_ptr(
const _Type&) noexcept
94 template<
typename _Tp, std::
size_t _Nm>
97 typedef _Tp value_type;
98 typedef value_type* pointer;
99 typedef const value_type* const_pointer;
100 typedef value_type& reference;
101 typedef const value_type& const_reference;
102 typedef value_type* iterator;
103 typedef const value_type* const_iterator;
104 typedef std::size_t size_type;
105 typedef std::ptrdiff_t difference_type;
110 typedef __array_traits<_Tp, _Nm> _AT_Type;
111 typename _AT_Type::_Type _M_elems;
116 _GLIBCXX20_CONSTEXPR
void
117 fill(
const value_type& __u)
120 _GLIBCXX20_CONSTEXPR
void
122 noexcept(_AT_Type::_Is_nothrow_swappable::value)
126 _GLIBCXX17_CONSTEXPR iterator
128 {
return iterator(data()); }
130 _GLIBCXX17_CONSTEXPR const_iterator
131 begin()
const noexcept
132 {
return const_iterator(data()); }
134 _GLIBCXX17_CONSTEXPR iterator
136 {
return iterator(data() + _Nm); }
138 _GLIBCXX17_CONSTEXPR const_iterator
140 {
return const_iterator(data() + _Nm); }
147 rbegin()
const noexcept
155 rend()
const noexcept
158 _GLIBCXX17_CONSTEXPR const_iterator
159 cbegin()
const noexcept
160 {
return const_iterator(data()); }
162 _GLIBCXX17_CONSTEXPR const_iterator
163 cend()
const noexcept
164 {
return const_iterator(data() + _Nm); }
167 crbegin()
const noexcept
171 crend()
const noexcept
176 size()
const noexcept {
return _Nm; }
179 max_size()
const noexcept {
return _Nm; }
181 _GLIBCXX_NODISCARD constexpr
bool
182 empty()
const noexcept {
return size() == 0; }
185 _GLIBCXX17_CONSTEXPR reference
186 operator[](size_type __n) noexcept
188 __glibcxx_requires_subscript(__n);
189 return _AT_Type::_S_ref(_M_elems, __n);
192 constexpr const_reference
193 operator[](size_type __n)
const noexcept
195 #if __cplusplus >= 201402L
196 __glibcxx_requires_subscript(__n);
198 return _AT_Type::_S_ref(_M_elems, __n);
201 _GLIBCXX17_CONSTEXPR reference
205 std::__throw_out_of_range_fmt(__N(
"array::at: __n (which is %zu) "
206 ">= _Nm (which is %zu)"),
208 return _AT_Type::_S_ref(_M_elems, __n);
211 constexpr const_reference
212 at(size_type __n)
const
216 return __n < _Nm ? _AT_Type::_S_ref(_M_elems, __n)
217 : (std::__throw_out_of_range_fmt(__N(
"array::at: __n (which is %zu) "
218 ">= _Nm (which is %zu)"),
220 _AT_Type::_S_ref(_M_elems, 0));
223 _GLIBCXX17_CONSTEXPR reference
226 __glibcxx_requires_nonempty();
230 constexpr const_reference
231 front()
const noexcept
233 #if __cplusplus >= 201402L
234 __glibcxx_requires_nonempty();
236 return _AT_Type::_S_ref(_M_elems, 0);
239 _GLIBCXX17_CONSTEXPR reference
242 __glibcxx_requires_nonempty();
243 return _Nm ? *(end() - 1) : *end();
246 constexpr const_reference
247 back()
const noexcept
249 #if __cplusplus >= 201402L
250 __glibcxx_requires_nonempty();
252 return _Nm ? _AT_Type::_S_ref(_M_elems, _Nm - 1)
253 : _AT_Type::_S_ref(_M_elems, 0);
256 _GLIBCXX17_CONSTEXPR pointer
258 {
return _AT_Type::_S_ptr(_M_elems); }
260 _GLIBCXX17_CONSTEXPR const_pointer
261 data()
const noexcept
262 {
return _AT_Type::_S_ptr(_M_elems); }
265 #if __cpp_deduction_guides >= 201606
266 template<
typename _Tp,
typename... _Up>
273 template<
typename _Tp, std::
size_t _Nm>
277 {
return std::equal(__one.begin(), __one.end(), __two.begin()); }
279 #if __cpp_lib_three_way_comparison && __cpp_lib_concepts
280 template<
typename _Tp,
size_t _Nm>
281 constexpr __detail::__synth3way_t<_Tp>
282 operator<=>(
const array<_Tp, _Nm>& __a,
const array<_Tp, _Nm>& __b)
284 #ifdef __cpp_lib_is_constant_evaluated
285 if constexpr (_Nm && __is_memcmp_ordered<_Tp>::__value)
286 if (!std::is_constant_evaluated())
288 constexpr
size_t __n = _Nm *
sizeof(_Tp);
289 return __builtin_memcmp(__a.data(), __b.data(), __n) <=> 0;
293 for (
size_t __i = 0; __i < _Nm; ++__i)
295 auto __c = __detail::__synth3way(__a[__i], __b[__i]);
299 return strong_ordering::equal;
302 template<
typename _Tp, std::
size_t _Nm>
305 operator!=(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
306 {
return !(__one == __two); }
308 template<
typename _Tp, std::
size_t _Nm>
311 operator<(const array<_Tp, _Nm>& __a,
const array<_Tp, _Nm>& __b)
314 __b.begin(), __b.end());
317 template<
typename _Tp, std::
size_t _Nm>
320 operator>(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
321 {
return __two < __one; }
323 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>
332 operator>=(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
333 {
return !(__one < __two); }
334 #endif // three_way_comparison && concepts
337 template<
typename _Tp, std::
size_t _Nm>
340 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
343 __array_traits<_Tp, _Nm>::_Is_swappable::value
348 swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
349 noexcept(noexcept(__one.swap(__two)))
350 { __one.swap(__two); }
352 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
353 template<
typename _Tp, std::
size_t _Nm>
355 !__array_traits<_Tp, _Nm>::_Is_swappable::value>::type
356 swap(array<_Tp, _Nm>&, array<_Tp, _Nm>&) =
delete;
359 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
361 get(array<_Tp, _Nm>& __arr) noexcept
363 static_assert(_Int < _Nm,
"array index is within bounds");
364 return __array_traits<_Tp, _Nm>::_S_ref(__arr._M_elems, _Int);
367 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
369 get(array<_Tp, _Nm>&& __arr) noexcept
371 static_assert(_Int < _Nm,
"array index is within bounds");
375 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
377 get(
const array<_Tp, _Nm>& __arr) noexcept
379 static_assert(_Int < _Nm,
"array index is within bounds");
380 return __array_traits<_Tp, _Nm>::_S_ref(__arr._M_elems, _Int);
383 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
384 constexpr
const _Tp&&
385 get(
const array<_Tp, _Nm>&& __arr) noexcept
387 static_assert(_Int < _Nm,
"array index is within bounds");
391 #if __cplusplus > 201703L
392 #define __cpp_lib_to_array 201907L
394 template<
bool _Move =
false,
typename _Tp,
size_t... _Idx>
395 constexpr array<remove_cv_t<_Tp>,
sizeof...(_Idx)>
396 __to_array(_Tp (&__a)[
sizeof...(_Idx)], index_sequence<_Idx...>)
401 return {{__a[_Idx]...}};
404 template<
typename _Tp,
size_t _Nm>
405 constexpr array<remove_cv_t<_Tp>, _Nm>
406 to_array(_Tp (&__a)[_Nm])
407 noexcept(is_nothrow_constructible_v<_Tp, _Tp&>)
409 static_assert(!is_array_v<_Tp>);
410 static_assert(is_constructible_v<_Tp, _Tp&>);
411 if constexpr (is_constructible_v<_Tp, _Tp&>)
413 __builtin_unreachable();
416 template<
typename _Tp,
size_t _Nm>
417 constexpr array<remove_cv_t<_Tp>, _Nm>
418 to_array(_Tp (&&__a)[_Nm])
419 noexcept(is_nothrow_move_constructible_v<_Tp>)
421 static_assert(!is_array_v<_Tp>);
422 static_assert(is_move_constructible_v<_Tp>);
423 if constexpr (is_move_constructible_v<_Tp>)
425 __builtin_unreachable();
432 template<
typename _Tp>
436 template<
typename _Tp, std::
size_t _Nm>
441 template<std::
size_t _Int,
typename _Tp>
445 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
448 static_assert(_Int < _Nm,
"index is out of bounds");
452 template<
typename _Tp, std::
size_t _Nm>
456 _GLIBCXX_END_NAMESPACE_VERSION
461 #endif // _GLIBCXX_ARRAY
constexpr bool equal(_IIter1 __first1, _IIter1 __last1, _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
Tests a range for element-wise equality.
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 _ForwardIterator2 swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
Swap the elements of two sequences.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
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.
constexpr _OI fill_n(_OI __first, _Size __n, const _Tp &__value)
Fills the range [first,first+n) with copies of value.