29 #ifndef _GLIBCXX_ARRAY
30 #define _GLIBCXX_ARRAY 1
32 #pragma GCC system_header
34 #if __cplusplus < 201103L
42 namespace std _GLIBCXX_VISIBILITY(default)
44 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
46 template<
typename _Tp, std::
size_t _Nm>
49 typedef _Tp _Type[_Nm];
52 _S_ref(
const _Type& __t, std::size_t __n) noexcept
53 {
return const_cast<_Tp&
>(__t[__n]); }
56 _S_ptr(
const _Type& __t) noexcept
57 {
return const_cast<_Tp*
>(__t); }
60 template<
typename _Tp>
61 struct __array_traits<_Tp, 0>
66 _S_ref(
const _Type&, std::size_t) noexcept
67 {
return *
static_cast<_Tp*
>(
nullptr); }
70 _S_ptr(
const _Type&) noexcept
88 template<
typename _Tp, std::
size_t _Nm>
91 typedef _Tp value_type;
92 typedef value_type* pointer;
93 typedef const value_type* const_pointer;
94 typedef value_type& reference;
95 typedef const value_type& const_reference;
96 typedef value_type* iterator;
97 typedef const value_type* const_iterator;
98 typedef std::size_t size_type;
99 typedef std::ptrdiff_t difference_type;
104 typedef _GLIBCXX_STD_C::__array_traits<_Tp, _Nm> _AT_Type;
105 typename _AT_Type::_Type _M_elems;
111 fill(
const value_type& __u)
116 noexcept(noexcept(
swap(std::declval<_Tp&>(), std::declval<_Tp&>())))
122 {
return iterator(data()); }
125 begin()
const noexcept
126 {
return const_iterator(data()); }
130 {
return iterator(data() + _Nm); }
134 {
return const_iterator(data() + _Nm); }
141 rbegin()
const noexcept
149 rend()
const noexcept
153 cbegin()
const noexcept
154 {
return const_iterator(data()); }
157 cend()
const noexcept
158 {
return const_iterator(data() + _Nm); }
161 crbegin()
const noexcept
165 crend()
const noexcept
170 size()
const noexcept {
return _Nm; }
173 max_size()
const noexcept {
return _Nm; }
176 empty()
const noexcept {
return size() == 0; }
180 operator[](size_type __n) noexcept
181 {
return _AT_Type::_S_ref(_M_elems, __n); }
183 constexpr const_reference
184 operator[](size_type __n)
const noexcept
185 {
return _AT_Type::_S_ref(_M_elems, __n); }
191 std::__throw_out_of_range_fmt(__N(
"array::at: __n (which is %zu) "
192 ">= _Nm (which is %zu)"),
194 return _AT_Type::_S_ref(_M_elems, __n);
197 constexpr const_reference
198 at(size_type __n)
const
202 return __n < _Nm ? _AT_Type::_S_ref(_M_elems, __n)
203 : (std::__throw_out_of_range_fmt(__N(
"array::at: __n (which is %zu) "
204 ">= _Nm (which is %zu)"),
206 _AT_Type::_S_ref(_M_elems, 0));
213 constexpr const_reference
214 front()
const noexcept
215 {
return _AT_Type::_S_ref(_M_elems, 0); }
219 {
return _Nm ? *(end() - 1) : *end(); }
221 constexpr const_reference
222 back()
const noexcept
224 return _Nm ? _AT_Type::_S_ref(_M_elems, _Nm - 1)
225 : _AT_Type::_S_ref(_M_elems, 0);
230 {
return _AT_Type::_S_ptr(_M_elems); }
233 data()
const noexcept
234 {
return _AT_Type::_S_ptr(_M_elems); }
238 template<
typename _Tp, std::
size_t _Nm>
241 {
return std::equal(__one.begin(), __one.end(), __two.begin()); }
243 template<
typename _Tp, std::
size_t _Nm>
245 operator!=(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
246 {
return !(__one == __two); }
248 template<
typename _Tp, std::
size_t _Nm>
250 operator<(const array<_Tp, _Nm>& __a,
const array<_Tp, _Nm>& __b)
253 __b.begin(), __b.end());
256 template<
typename _Tp, std::
size_t _Nm>
258 operator>(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
259 {
return __two < __one; }
261 template<
typename _Tp, std::
size_t _Nm>
263 operator<=(const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
264 {
return !(__one > __two); }
266 template<
typename _Tp, std::
size_t _Nm>
268 operator>=(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
269 {
return !(__one < __two); }
272 template<
typename _Tp, std::
size_t _Nm>
274 swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
275 noexcept(noexcept(__one.swap(__two)))
276 { __one.swap(__two); }
278 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
280 get(array<_Tp, _Nm>&
__arr) noexcept
282 static_assert(_Int < _Nm,
"index is out of bounds");
283 return _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>::
284 _S_ref(
__arr._M_elems, _Int);
287 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
289 get(array<_Tp, _Nm>&&
__arr) noexcept
291 static_assert(_Int < _Nm,
"index is out of bounds");
292 return std::move(_GLIBCXX_STD_C::get<_Int>(
__arr));
295 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
297 get(
const array<_Tp, _Nm>&
__arr) noexcept
299 static_assert(_Int < _Nm,
"index is out of bounds");
300 return _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>::
301 _S_ref(
__arr._M_elems, _Int);
304 _GLIBCXX_END_NAMESPACE_CONTAINER
307 namespace std _GLIBCXX_VISIBILITY(default)
309 _GLIBCXX_BEGIN_NAMESPACE_VERSION
314 template<
typename _Tp>
318 template<
typename _Tp, std::
size_t _Nm>
323 template<std::
size_t _Int,
typename _Tp>
327 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
330 static_assert(_Int < _Nm,
"index is out of bounds");
334 _GLIBCXX_END_NAMESPACE_VERSION
337 #ifdef _GLIBCXX_DEBUG
341 #ifdef _GLIBCXX_PROFILE
342 # include <profile/array>
347 #endif // _GLIBCXX_ARRAY
_OI fill_n(_OI __first, _Size __n, const _Tp &__value)
Fills the range [first,first+n) with copies of value.
_GLIBCXX14_CONSTEXPR _Tp *return __arr
Return an iterator pointing to the first element of the array.
bool equal(_IIter1 __first1, _IIter1 __last1, _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
Tests a range for element-wise equality.
_ForwardIterator2 swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
Swap the elements of two sequences.
A standard container for storing a fixed size sequence of elements.
bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
void swap(basic_filebuf< _CharT, _Traits > &__x, basic_filebuf< _CharT, _Traits > &__y)
Swap specialization for filebufs.