123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- #ifndef _GLIBCXX_ARRAY
- #define _GLIBCXX_ARRAY 1
- #pragma GCC system_header
- #if __cplusplus < 201103L
- # include <bits/c++0x_warning.h>
- #else
- #include <stdexcept>
- #include <bits/stl_algobase.h>
- #include <bits/range_access.h>
- namespace std _GLIBCXX_VISIBILITY(default)
- {
- _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
- template<typename _Tp, std::size_t _Nm>
- struct __array_traits
- {
- typedef _Tp _Type[_Nm];
- static constexpr _Tp&
- _S_ref(const _Type& __t, std::size_t __n) noexcept
- { return const_cast<_Tp&>(__t[__n]); }
- static constexpr _Tp*
- _S_ptr(const _Type& __t) noexcept
- { return const_cast<_Tp*>(__t); }
- };
- template<typename _Tp>
- struct __array_traits<_Tp, 0>
- {
- struct _Type { };
- static constexpr _Tp&
- _S_ref(const _Type&, std::size_t) noexcept
- { return *static_cast<_Tp*>(nullptr); }
- static constexpr _Tp*
- _S_ptr(const _Type&) noexcept
- { return nullptr; }
- };
-
- template<typename _Tp, std::size_t _Nm>
- struct array
- {
- typedef _Tp value_type;
- typedef value_type* pointer;
- typedef const value_type* const_pointer;
- typedef value_type& reference;
- typedef const value_type& const_reference;
- typedef value_type* iterator;
- typedef const value_type* const_iterator;
- typedef std::size_t size_type;
- typedef std::ptrdiff_t difference_type;
- typedef std::reverse_iterator<iterator> reverse_iterator;
- typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
-
- typedef _GLIBCXX_STD_C::__array_traits<_Tp, _Nm> _AT_Type;
- typename _AT_Type::_Type _M_elems;
-
-
- void
- fill(const value_type& __u)
- { std::fill_n(begin(), size(), __u); }
- void
- swap(array& __other)
- noexcept(noexcept(swap(std::declval<_Tp&>(), std::declval<_Tp&>())))
- { std::swap_ranges(begin(), end(), __other.begin()); }
-
- iterator
- begin() noexcept
- { return iterator(data()); }
- const_iterator
- begin() const noexcept
- { return const_iterator(data()); }
- iterator
- end() noexcept
- { return iterator(data() + _Nm); }
- const_iterator
- end() const noexcept
- { return const_iterator(data() + _Nm); }
- reverse_iterator
- rbegin() noexcept
- { return reverse_iterator(end()); }
- const_reverse_iterator
- rbegin() const noexcept
- { return const_reverse_iterator(end()); }
- reverse_iterator
- rend() noexcept
- { return reverse_iterator(begin()); }
- const_reverse_iterator
- rend() const noexcept
- { return const_reverse_iterator(begin()); }
- const_iterator
- cbegin() const noexcept
- { return const_iterator(data()); }
- const_iterator
- cend() const noexcept
- { return const_iterator(data() + _Nm); }
- const_reverse_iterator
- crbegin() const noexcept
- { return const_reverse_iterator(end()); }
- const_reverse_iterator
- crend() const noexcept
- { return const_reverse_iterator(begin()); }
-
- constexpr size_type
- size() const noexcept { return _Nm; }
- constexpr size_type
- max_size() const noexcept { return _Nm; }
- constexpr bool
- empty() const noexcept { return size() == 0; }
-
- reference
- operator[](size_type __n) noexcept
- { return _AT_Type::_S_ref(_M_elems, __n); }
- constexpr const_reference
- operator[](size_type __n) const noexcept
- { return _AT_Type::_S_ref(_M_elems, __n); }
- reference
- at(size_type __n)
- {
- if (__n >= _Nm)
- std::__throw_out_of_range_fmt(__N("array::at: __n (which is %zu) "
- ">= _Nm (which is %zu)"),
- __n, _Nm);
- return _AT_Type::_S_ref(_M_elems, __n);
- }
- constexpr const_reference
- at(size_type __n) const
- {
-
-
- return __n < _Nm ? _AT_Type::_S_ref(_M_elems, __n)
- : (std::__throw_out_of_range_fmt(__N("array::at: __n (which is %zu) "
- ">= _Nm (which is %zu)"),
- __n, _Nm),
- _AT_Type::_S_ref(_M_elems, 0));
- }
- reference
- front() noexcept
- { return *begin(); }
- constexpr const_reference
- front() const noexcept
- { return _AT_Type::_S_ref(_M_elems, 0); }
- reference
- back() noexcept
- { return _Nm ? *(end() - 1) : *end(); }
- constexpr const_reference
- back() const noexcept
- {
- return _Nm ? _AT_Type::_S_ref(_M_elems, _Nm - 1)
- : _AT_Type::_S_ref(_M_elems, 0);
- }
- pointer
- data() noexcept
- { return _AT_Type::_S_ptr(_M_elems); }
- const_pointer
- data() const noexcept
- { return _AT_Type::_S_ptr(_M_elems); }
- };
-
- template<typename _Tp, std::size_t _Nm>
- inline bool
- operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
- { return std::equal(__one.begin(), __one.end(), __two.begin()); }
- template<typename _Tp, std::size_t _Nm>
- inline bool
- operator!=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
- { return !(__one == __two); }
- template<typename _Tp, std::size_t _Nm>
- inline bool
- operator<(const array<_Tp, _Nm>& __a, const array<_Tp, _Nm>& __b)
- {
- return std::lexicographical_compare(__a.begin(), __a.end(),
- __b.begin(), __b.end());
- }
- template<typename _Tp, std::size_t _Nm>
- inline bool
- operator>(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
- { return __two < __one; }
- template<typename _Tp, std::size_t _Nm>
- inline bool
- operator<=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
- { return !(__one > __two); }
- template<typename _Tp, std::size_t _Nm>
- inline bool
- operator>=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
- { return !(__one < __two); }
-
- template<typename _Tp, std::size_t _Nm>
- inline void
- swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
- noexcept(noexcept(__one.swap(__two)))
- { __one.swap(__two); }
- template<std::size_t _Int, typename _Tp, std::size_t _Nm>
- constexpr _Tp&
- get(array<_Tp, _Nm>& __arr) noexcept
- {
- static_assert(_Int < _Nm, "index is out of bounds");
- return _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>::
- _S_ref(__arr._M_elems, _Int);
- }
- template<std::size_t _Int, typename _Tp, std::size_t _Nm>
- constexpr _Tp&&
- get(array<_Tp, _Nm>&& __arr) noexcept
- {
- static_assert(_Int < _Nm, "index is out of bounds");
- return std::move(_GLIBCXX_STD_C::get<_Int>(__arr));
- }
- template<std::size_t _Int, typename _Tp, std::size_t _Nm>
- constexpr const _Tp&
- get(const array<_Tp, _Nm>& __arr) noexcept
- {
- static_assert(_Int < _Nm, "index is out of bounds");
- return _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>::
- _S_ref(__arr._M_elems, _Int);
- }
- _GLIBCXX_END_NAMESPACE_CONTAINER
- }
- namespace std _GLIBCXX_VISIBILITY(default)
- {
- _GLIBCXX_BEGIN_NAMESPACE_VERSION
-
-
- template<typename _Tp>
- class tuple_size;
-
- template<typename _Tp, std::size_t _Nm>
- struct tuple_size<_GLIBCXX_STD_C::array<_Tp, _Nm>>
- : public integral_constant<std::size_t, _Nm> { };
-
- template<std::size_t _Int, typename _Tp>
- class tuple_element;
-
- template<std::size_t _Int, typename _Tp, std::size_t _Nm>
- struct tuple_element<_Int, _GLIBCXX_STD_C::array<_Tp, _Nm>>
- {
- static_assert(_Int < _Nm, "index is out of bounds");
- typedef _Tp type;
- };
- _GLIBCXX_END_NAMESPACE_VERSION
- }
- #ifdef _GLIBCXX_DEBUG
- # include <debug/array>
- #endif
- #ifdef _GLIBCXX_PROFILE
- # include <profile/array>
- #endif
- #endif
- #endif
|