29 #ifndef _GLIBCXX_DEBUG_ARRAY
30 #define _GLIBCXX_DEBUG_ARRAY 1
32 #pragma GCC system_header
39 namespace std _GLIBCXX_VISIBILITY(default)
43 template<
typename _Tp, std::
size_t _Nm>
46 typedef _Tp value_type;
47 typedef value_type* pointer;
48 typedef const value_type* const_pointer;
49 typedef value_type& reference;
50 typedef const value_type& const_reference;
51 typedef value_type* iterator;
52 typedef const value_type* const_iterator;
53 typedef std::size_t size_type;
54 typedef std::ptrdiff_t difference_type;
59 typedef _GLIBCXX_STD_C::__array_traits<_Tp, _Nm> _AT_Type;
60 typename _AT_Type::_Type _M_elems;
62 template<std::
size_t _Size>
63 struct _Array_check_subscript
65 std::size_t size() {
return _Size; }
67 _Array_check_subscript(std::size_t __index)
68 { __glibcxx_check_subscript(__index); }
71 template<std::
size_t _Size>
72 struct _Array_check_nonempty
74 _GLIBCXX_NODISCARD
bool empty() {
return _Size == 0; }
76 _Array_check_nonempty()
77 { __glibcxx_check_nonempty(); }
83 _GLIBCXX20_CONSTEXPR
void
84 fill(
const value_type& __u)
87 _GLIBCXX20_CONSTEXPR
void
89 noexcept(_AT_Type::_Is_nothrow_swappable::value)
93 _GLIBCXX17_CONSTEXPR iterator
95 {
return iterator(data()); }
97 _GLIBCXX17_CONSTEXPR const_iterator
98 begin() const noexcept
99 {
return const_iterator(data()); }
101 _GLIBCXX17_CONSTEXPR iterator
103 {
return iterator(data() + _Nm); }
105 _GLIBCXX17_CONSTEXPR const_iterator
107 {
return const_iterator(data() + _Nm); }
109 _GLIBCXX17_CONSTEXPR reverse_iterator
111 {
return reverse_iterator(
end()); }
113 _GLIBCXX17_CONSTEXPR const_reverse_iterator
115 {
return const_reverse_iterator(
end()); }
117 _GLIBCXX17_CONSTEXPR reverse_iterator
119 {
return reverse_iterator(
begin()); }
121 _GLIBCXX17_CONSTEXPR const_reverse_iterator
122 rend() const noexcept
123 {
return const_reverse_iterator(
begin()); }
125 _GLIBCXX17_CONSTEXPR const_iterator
127 {
return const_iterator(data()); }
129 _GLIBCXX17_CONSTEXPR const_iterator
130 cend() const noexcept
131 {
return const_iterator(data() + _Nm); }
133 _GLIBCXX17_CONSTEXPR const_reverse_iterator
135 {
return const_reverse_iterator(
end()); }
137 _GLIBCXX17_CONSTEXPR const_reverse_iterator
138 crend() const noexcept
139 {
return const_reverse_iterator(
begin()); }
143 size() const noexcept {
return _Nm; }
146 max_size() const noexcept {
return _Nm; }
148 _GLIBCXX_NODISCARD constexpr
bool
149 empty() const noexcept {
return size() == 0; }
152 _GLIBCXX17_CONSTEXPR reference
153 operator[](size_type __n) noexcept
155 __glibcxx_check_subscript(__n);
156 return _AT_Type::_S_ref(_M_elems, __n);
159 constexpr const_reference
160 operator[](size_type __n)
const noexcept
162 return __n < _Nm ? _AT_Type::_S_ref(_M_elems, __n)
163 : (_GLIBCXX_THROW_OR_ABORT(_Array_check_subscript<_Nm>(__n)),
164 _AT_Type::_S_ref(_M_elems, 0));
167 _GLIBCXX17_CONSTEXPR reference
171 std::__throw_out_of_range_fmt(__N(
"array::at: __n (which is %zu) "
172 ">= _Nm (which is %zu)"),
174 return _AT_Type::_S_ref(_M_elems, __n);
177 constexpr const_reference
178 at(size_type __n)
const
182 return __n < _Nm ? _AT_Type::_S_ref(_M_elems, __n)
183 : (std::__throw_out_of_range_fmt(__N(
"array::at: __n (which is %zu) "
184 ">= _Nm (which is %zu)"),
186 _AT_Type::_S_ref(_M_elems, 0));
189 _GLIBCXX17_CONSTEXPR reference
192 __glibcxx_check_nonempty();
196 constexpr const_reference
197 front() const noexcept
199 return _Nm ? _AT_Type::_S_ref(_M_elems, 0)
200 : (_GLIBCXX_THROW_OR_ABORT(_Array_check_nonempty<_Nm>()),
201 _AT_Type::_S_ref(_M_elems, 0));
204 _GLIBCXX17_CONSTEXPR reference
207 __glibcxx_check_nonempty();
208 return _Nm ? *(
end() - 1) : *
end();
211 constexpr const_reference
212 back() const noexcept
214 return _Nm ? _AT_Type::_S_ref(_M_elems, _Nm - 1)
215 : (_GLIBCXX_THROW_OR_ABORT(_Array_check_nonempty<_Nm>()),
216 _AT_Type::_S_ref(_M_elems, 0));
219 _GLIBCXX17_CONSTEXPR pointer
221 {
return _AT_Type::_S_ptr(_M_elems); }
223 _GLIBCXX17_CONSTEXPR const_pointer
224 data() const noexcept
225 {
return _AT_Type::_S_ptr(_M_elems); }
228 #if __cpp_deduction_guides >= 201606
229 template<
typename _Tp,
typename... _Up>
231 -> array<std::enable_if_t<(std::is_same_v<_Tp, _Up> && ...), _Tp>,
236 template<
typename _Tp, std::
size_t _Nm>
239 operator==(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
240 {
return std::equal(__one.begin(), __one.end(), __two.begin()); }
242 #if __cpp_lib_three_way_comparison && __cpp_lib_concepts
243 template<
typename _Tp,
size_t _Nm>
244 constexpr __detail::__synth3way_t<_Tp>
245 operator<=>(
const array<_Tp, _Nm>& __a,
const array<_Tp, _Nm>& __b)
247 if constexpr (_Nm && __is_byte<_Tp>::__value)
248 return __builtin_memcmp(__a.data(), __b.data(), _Nm) <=> 0;
251 for (
size_t __i = 0; __i < _Nm; ++__i)
253 auto __c = __detail::__synth3way(__a[__i], __b[__i]);
258 return strong_ordering::equal;
261 template<
typename _Tp, std::
size_t _Nm>
264 operator!=(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
265 {
return !(__one == __two); }
267 template<
typename _Tp, std::
size_t _Nm>
270 operator<(const array<_Tp, _Nm>& __a,
const array<_Tp, _Nm>& __b)
273 __b.begin(), __b.end());
276 template<
typename _Tp, std::
size_t _Nm>
279 operator>(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
280 {
return __two < __one; }
282 template<
typename _Tp, std::
size_t _Nm>
285 operator<=(const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
286 {
return !(__one > __two); }
288 template<
typename _Tp, std::
size_t _Nm>
291 operator>=(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
292 {
return !(__one < __two); }
293 #endif // three_way_comparison && concepts
297 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
298 template<
typename _Tp,
size_t _Nm>
300 !_GLIBCXX_STD_C::__array_traits<_Tp, _Nm>::_Is_swappable::value>::type
301 swap(array<_Tp, _Nm>&, array<_Tp, _Nm>&) =
delete;
304 template<
typename _Tp, std::
size_t _Nm>
307 swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
308 noexcept(noexcept(__one.swap(__two)))
309 { __one.swap(__two); }
311 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
313 get(array<_Tp, _Nm>& __arr) noexcept
315 static_assert(_Int < _Nm,
"index is out of bounds");
316 return _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>::
317 _S_ref(__arr._M_elems, _Int);
320 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
322 get(array<_Tp, _Nm>&& __arr) noexcept
324 static_assert(_Int < _Nm,
"index is out of bounds");
325 return std::move(__debug::get<_Int>(__arr));
328 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
330 get(
const array<_Tp, _Nm>& __arr) noexcept
332 static_assert(_Int < _Nm,
"index is out of bounds");
333 return _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>::
334 _S_ref(__arr._M_elems, _Int);
337 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
338 constexpr
const _Tp&&
339 get(
const array<_Tp, _Nm>&& __arr) noexcept
341 static_assert(_Int < _Nm,
"index is out of bounds");
342 return std::move(__debug::get<_Int>(__arr));
345 #if __cplusplus > 201703L
346 #define __cpp_lib_to_array 201907L
348 template<
bool _Move =
false,
typename _Tp,
size_t... _Idx>
349 constexpr array<remove_cv_t<_Tp>,
sizeof...(_Idx)>
350 __to_array(_Tp (&__a)[
sizeof...(_Idx)], index_sequence<_Idx...>)
355 return {{__a[_Idx]...}};
358 template<
typename _Tp,
size_t _Nm>
359 constexpr array<remove_cv_t<_Tp>, _Nm>
360 to_array(_Tp (&__a)[_Nm])
361 noexcept(is_nothrow_constructible_v<_Tp, _Tp&>)
363 static_assert(!is_array_v<_Tp>);
364 static_assert(is_constructible_v<_Tp, _Tp&>);
365 if constexpr (is_constructible_v<_Tp, _Tp&>)
367 __builtin_unreachable();
370 template<
typename _Tp,
size_t _Nm>
371 constexpr array<remove_cv_t<_Tp>, _Nm>
372 to_array(_Tp (&&__a)[_Nm])
373 noexcept(is_nothrow_move_constructible_v<_Tp>)
375 static_assert(!is_array_v<_Tp>);
376 static_assert(is_move_constructible_v<_Tp>);
377 if constexpr (is_move_constructible_v<_Tp>)
379 __builtin_unreachable();
385 _GLIBCXX_BEGIN_NAMESPACE_VERSION
389 template<
typename _Tp, std::
size_t _Nm>
394 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
397 static_assert(_Int < _Nm,
"index is out of bounds");
401 template<
typename _Tp, std::
size_t _Nm>
402 struct __is_tuple_like_impl<std::__debug::array<_Tp, _Nm>> :
true_type
405 _GLIBCXX_END_NAMESPACE_VERSION
408 #endif // _GLIBCXX_DEBUG_ARRAY
constexpr auto rend(_Container &__cont) -> decltype(__cont.rend())
Return a reverse iterator pointing one past the first element of the container.
_Tp * begin(valarray< _Tp > &__va)
Return an iterator pointing to the first element of the valarray.
constexpr auto crend(const _Container &__cont) -> decltype(std::rend(__cont))
Return a reverse iterator pointing one past the first element of the const container.
make_integer_sequence< size_t, _Num > make_index_sequence
Alias template make_index_sequence.
constexpr auto crbegin(const _Container &__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.
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.
constexpr _OI fill_n(_OI __first, _Size __n, const _Tp &__value)
Fills the range [first,first+n) with copies of value.
constexpr auto rbegin(_Container &__cont) -> decltype(__cont.rbegin())
Return a reverse iterator pointing to the last element of the container.
constexpr bool equal(_IIter1 __first1, _IIter1 __last1, _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
Tests a range for element-wise equality.
_Tp * end(valarray< _Tp > &__va)
Return an iterator pointing to one past the last element of the valarray.
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 _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.