29 #ifndef _GLIBCXX_DEBUG_ARRAY
30 #define _GLIBCXX_DEBUG_ARRAY 1
32 #pragma GCC system_header
36 namespace std _GLIBCXX_VISIBILITY(default)
40 template<
typename _Tp, std::
size_t _Nm>
43 typedef _Tp value_type;
44 typedef value_type* pointer;
45 typedef const value_type* const_pointer;
46 typedef value_type& reference;
47 typedef const value_type& const_reference;
48 typedef value_type* iterator;
49 typedef const value_type* const_iterator;
50 typedef std::size_t size_type;
51 typedef std::ptrdiff_t difference_type;
56 typedef _GLIBCXX_STD_C::__array_traits<_Tp, _Nm> _AT_Type;
57 typename _AT_Type::_Type _M_elems;
59 template<std::
size_t _Size>
60 struct _Array_check_subscript
62 std::size_t size() {
return _Size; }
64 _Array_check_subscript(std::size_t __index)
65 { __glibcxx_check_subscript(__index); }
68 template<std::
size_t _Size>
69 struct _Array_check_nonempty
71 bool empty() {
return _Size == 0; }
73 _Array_check_nonempty()
74 { __glibcxx_check_nonempty(); }
81 fill(
const value_type& __u)
86 noexcept(noexcept(swap(std::declval<_Tp&>(), std::declval<_Tp&>())))
92 {
return iterator(data()); }
95 begin() const noexcept
96 {
return const_iterator(data()); }
100 {
return iterator(data() + _Nm); }
104 {
return const_iterator(data() + _Nm); }
108 {
return reverse_iterator(
end()); }
110 const_reverse_iterator
112 {
return const_reverse_iterator(
end()); }
116 {
return reverse_iterator(
begin()); }
118 const_reverse_iterator
119 rend() const noexcept
120 {
return const_reverse_iterator(
begin()); }
124 {
return const_iterator(data()); }
127 cend() const noexcept
128 {
return const_iterator(data() + _Nm); }
130 const_reverse_iterator
132 {
return const_reverse_iterator(
end()); }
134 const_reverse_iterator
135 crend() const noexcept
136 {
return const_reverse_iterator(
begin()); }
140 size() const noexcept {
return _Nm; }
143 max_size() const noexcept {
return _Nm; }
146 empty() const noexcept {
return size() == 0; }
150 operator[](size_type __n) noexcept
152 __glibcxx_check_subscript(__n);
153 return _AT_Type::_S_ref(_M_elems, __n);
156 constexpr const_reference
157 operator[](size_type __n)
const noexcept
159 return __n < _Nm ? _AT_Type::_S_ref(_M_elems, __n)
160 : (_GLIBCXX_THROW_OR_ABORT(_Array_check_subscript<_Nm>(__n)),
161 _AT_Type::_S_ref(_M_elems, 0));
168 std::__throw_out_of_range_fmt(__N(
"array::at: __n "
169 "(which is %zu) >= _Nm "
172 return _AT_Type::_S_ref(_M_elems, __n);
175 constexpr const_reference
176 at(size_type __n)
const
180 return __n < _Nm ? _AT_Type::_S_ref(_M_elems, __n)
181 : (std::__throw_out_of_range_fmt(__N(
"array::at: __n (which is %zu) "
182 ">= _Nm (which is %zu)"),
184 _AT_Type::_S_ref(_M_elems, 0));
190 __glibcxx_check_nonempty();
194 constexpr const_reference
195 front() const noexcept
197 return _Nm ? _AT_Type::_S_ref(_M_elems, 0)
198 : (_GLIBCXX_THROW_OR_ABORT(_Array_check_nonempty<_Nm>()),
199 _AT_Type::_S_ref(_M_elems, 0));
205 __glibcxx_check_nonempty();
206 return _Nm ? *(
end() - 1) : *
end();
209 constexpr const_reference
210 back() const noexcept
212 return _Nm ? _AT_Type::_S_ref(_M_elems, _Nm - 1)
213 : (_GLIBCXX_THROW_OR_ABORT(_Array_check_nonempty<_Nm>()),
214 _AT_Type::_S_ref(_M_elems, 0));
219 {
return _AT_Type::_S_ptr(_M_elems); }
222 data() const noexcept
223 {
return _AT_Type::_S_ptr(_M_elems); }
227 template<
typename _Tp, std::
size_t _Nm>
229 operator==(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
230 {
return std::equal(__one.begin(), __one.end(), __two.begin()); }
232 template<
typename _Tp, std::
size_t _Nm>
234 operator!=(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
235 {
return !(__one == __two); }
237 template<
typename _Tp, std::
size_t _Nm>
239 operator<(const array<_Tp, _Nm>& __a,
const array<_Tp, _Nm>& __b)
242 __b.begin(), __b.end());
245 template<
typename _Tp, std::
size_t _Nm>
247 operator>(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
248 {
return __two < __one; }
250 template<
typename _Tp, std::
size_t _Nm>
252 operator<=(const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
253 {
return !(__one > __two); }
255 template<
typename _Tp, std::
size_t _Nm>
257 operator>=(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
258 {
return !(__one < __two); }
261 template<
typename _Tp, std::
size_t _Nm>
263 swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
264 noexcept(noexcept(__one.swap(__two)))
265 { __one.swap(__two); }
267 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
269 get(array<_Tp, _Nm>& __arr) noexcept
271 static_assert(_Int < _Nm,
"index is out of bounds");
272 return _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>::
273 _S_ref(__arr._M_elems, _Int);
276 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
278 get(array<_Tp, _Nm>&& __arr) noexcept
280 static_assert(_Int < _Nm,
"index is out of bounds");
281 return std::move(__debug::get<_Int>(__arr));
284 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
286 get(
const array<_Tp, _Nm>& __arr) noexcept
288 static_assert(_Int < _Nm,
"index is out of bounds");
289 return _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>::
290 _S_ref(__arr._M_elems, _Int);
297 template<
typename _Tp, std::
size_t _Nm>
302 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
305 static_assert(_Int < _Nm,
"index is out of bounds");
310 #endif // _GLIBCXX_DEBUG_ARRAY
bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
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.
auto rend(_Container &__cont) -> decltype(__cont.rend())
Return a reverse iterator pointing one past the first element of the container.
bool equal(_IIter1 __first1, _IIter1 __last1, _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
Tests a range for element-wise equality.
_OI fill_n(_OI __first, _Size __n, const _Tp &__value)
Fills the range [first,first+n) with copies of value.
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initializer_list.
A standard container for storing a fixed size sequence of elements.
_ForwardIterator2 swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
Swap the elements of two sequences.
auto crend(const _Container &__cont) -> decltype(std::rend(__cont))
Return a reverse iterator pointing one past the first element of the const container.
auto rbegin(_Container &__cont) -> decltype(__cont.rbegin())
Return a reverse iterator pointing to the last element of the container.
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list. ...
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.
auto crbegin(const _Container &__cont) -> decltype(std::rbegin(__cont))
Return a reverse iterator pointing to the last element of the const container.