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 template<
typename _Tp>
57 struct __array_traits<_Tp, 0>
62 _S_ref(
const _Type&, std::size_t) noexcept
63 {
return *
static_cast<_Tp*
>(
nullptr); }
80 template<
typename _Tp, std::
size_t _Nm>
83 typedef _Tp value_type;
84 typedef value_type* pointer;
85 typedef const value_type* const_pointer;
86 typedef value_type& reference;
87 typedef const value_type& const_reference;
88 typedef value_type* iterator;
89 typedef const value_type* const_iterator;
90 typedef std::size_t size_type;
91 typedef std::ptrdiff_t difference_type;
96 typedef _GLIBCXX_STD_C::__array_traits<_Tp, _Nm> _AT_Type;
97 typename _AT_Type::_Type _M_elems;
103 fill(
const value_type& __u)
108 noexcept(noexcept(
swap(std::declval<_Tp&>(), std::declval<_Tp&>())))
114 {
return iterator(data()); }
117 begin()
const noexcept
118 {
return const_iterator(data()); }
122 {
return iterator(data() + _Nm); }
126 {
return const_iterator(data() + _Nm); }
133 rbegin()
const noexcept
141 rend()
const noexcept
145 cbegin()
const noexcept
146 {
return const_iterator(data()); }
149 cend()
const noexcept
150 {
return const_iterator(data() + _Nm); }
153 crbegin()
const noexcept
157 crend()
const noexcept
162 size()
const noexcept {
return _Nm; }
165 max_size()
const noexcept {
return _Nm; }
168 empty()
const noexcept {
return size() == 0; }
172 operator[](size_type __n) noexcept
173 {
return _AT_Type::_S_ref(_M_elems, __n); }
175 constexpr const_reference
176 operator[](size_type __n)
const noexcept
177 {
return _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 return _AT_Type::_S_ref(_M_elems, __n);
189 constexpr const_reference
190 at(size_type __n)
const
194 return __n < _Nm ? _AT_Type::_S_ref(_M_elems, __n)
195 : (std::__throw_out_of_range_fmt(__N(
"array::at: __n (which is %zu) "
196 ">= _Nm (which is %zu)"),
198 _AT_Type::_S_ref(_M_elems, 0));
205 constexpr const_reference
206 front()
const noexcept
207 {
return _AT_Type::_S_ref(_M_elems, 0); }
211 {
return _Nm ? *(end() - 1) : *end(); }
213 constexpr const_reference
214 back()
const noexcept
216 return _Nm ? _AT_Type::_S_ref(_M_elems, _Nm - 1)
217 : _AT_Type::_S_ref(_M_elems, 0);
225 data()
const noexcept
230 template<
typename _Tp, std::
size_t _Nm>
233 {
return std::equal(__one.begin(), __one.end(), __two.begin()); }
235 template<
typename _Tp, std::
size_t _Nm>
237 operator!=(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
238 {
return !(__one == __two); }
240 template<
typename _Tp, std::
size_t _Nm>
242 operator<(const array<_Tp, _Nm>& __a,
const array<_Tp, _Nm>& __b)
245 __b.begin(), __b.end());
248 template<
typename _Tp, std::
size_t _Nm>
250 operator>(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
251 {
return __two < __one; }
253 template<
typename _Tp, std::
size_t _Nm>
255 operator<=(const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
256 {
return !(__one > __two); }
258 template<
typename _Tp, std::
size_t _Nm>
260 operator>=(
const array<_Tp, _Nm>& __one,
const array<_Tp, _Nm>& __two)
261 {
return !(__one < __two); }
264 template<
typename _Tp, std::
size_t _Nm>
266 swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
267 noexcept(noexcept(__one.swap(__two)))
268 { __one.swap(__two); }
270 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
272 get(array<_Tp, _Nm>&
__arr) noexcept
274 static_assert(_Int < _Nm,
"index is out of bounds");
275 return _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>::
276 _S_ref(
__arr._M_elems, _Int);
279 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
281 get(array<_Tp, _Nm>&&
__arr) noexcept
283 static_assert(_Int < _Nm,
"index is out of bounds");
284 return std::move(get<_Int>(
__arr));
287 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
289 get(
const array<_Tp, _Nm>&
__arr) noexcept
291 static_assert(_Int < _Nm,
"index is out of bounds");
292 return _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>::
293 _S_ref(
__arr._M_elems, _Int);
296 _GLIBCXX_END_NAMESPACE_CONTAINER
299 namespace std _GLIBCXX_VISIBILITY(default)
301 _GLIBCXX_BEGIN_NAMESPACE_VERSION
306 template<
typename _Tp>
309 template<
typename _Tp, std::
size_t _Nm>
314 template<std::
size_t _Int,
typename _Tp>
317 template<std::
size_t _Int,
typename _Tp, std::
size_t _Nm>
320 static_assert(_Int < _Nm,
"index is out of bounds");
324 _GLIBCXX_END_NAMESPACE_VERSION
327 #ifdef _GLIBCXX_DEBUG
328 # include <debug/array>
331 #ifdef _GLIBCXX_PROFILE
332 # include <profile/array>
337 #endif // _GLIBCXX_ARRAY
_ForwardIterator2 swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
Swap the elements of two sequences.
_Tp *return __arr
Return an iterator pointing to the first element of the array.
A standard container for storing a fixed size sequence of elements.
bool equal(_II1 __first1, _II1 __last1, _II2 __first2)
Tests a range for element-wise equality.
void swap(function< _Res(_Args...)> &__x, function< _Res(_Args...)> &__y)
Swap the targets of two polymorphic function object wrappers.
_Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
_OI fill_n(_OI __first, _Size __n, const _Tp &__value)
Fills the range [first,first+n) with copies of value.