123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593 |
- #ifndef _POINTER_H
- #define _POINTER_H 1
- #pragma GCC system_header
- #include <iosfwd>
- #include <bits/stl_iterator_base_types.h>
- #include <ext/cast.h>
- #include <ext/type_traits.h>
- #if __cplusplus >= 201103L
- # include <bits/move.h>
- # include <bits/ptr_traits.h>
- #endif
- namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
- {
- _GLIBCXX_BEGIN_NAMESPACE_VERSION
-
- template<typename _Tp>
- class _Std_pointer_impl
- {
- public:
-
- typedef _Tp element_type;
-
-
- inline _Tp*
- get() const
- { return _M_value; }
-
-
- inline void
- set(element_type* __arg)
- { _M_value = __arg; }
-
-
- inline bool
- operator<(const _Std_pointer_impl& __rarg) const
- { return (_M_value < __rarg._M_value); }
-
- inline bool
- operator==(const _Std_pointer_impl& __rarg) const
- { return (_M_value == __rarg._M_value); }
- private:
- element_type* _M_value;
- };
-
- template<typename _Tp>
- class _Relative_pointer_impl
- {
- public:
- typedef _Tp element_type;
-
- _Tp*
- get() const
- {
- if (_M_diff == 1)
- return 0;
- else
- return reinterpret_cast<_Tp*>(reinterpret_cast<_UIntPtrType>(this)
- + _M_diff);
- }
-
- void
- set(_Tp* __arg)
- {
- if (!__arg)
- _M_diff = 1;
- else
- _M_diff = reinterpret_cast<_UIntPtrType>(__arg)
- - reinterpret_cast<_UIntPtrType>(this);
- }
-
-
- inline bool
- operator<(const _Relative_pointer_impl& __rarg) const
- { return (reinterpret_cast<_UIntPtrType>(this->get())
- < reinterpret_cast<_UIntPtrType>(__rarg.get())); }
- inline bool
- operator==(const _Relative_pointer_impl& __rarg) const
- { return (reinterpret_cast<_UIntPtrType>(this->get())
- == reinterpret_cast<_UIntPtrType>(__rarg.get())); }
- private:
- #ifdef _GLIBCXX_USE_LONG_LONG
- typedef __gnu_cxx::__conditional_type<
- (sizeof(unsigned long) >= sizeof(void*)),
- unsigned long, unsigned long long>::__type _UIntPtrType;
- #else
- typedef unsigned long _UIntPtrType;
- #endif
- _UIntPtrType _M_diff;
- };
-
-
- template<typename _Tp>
- class _Relative_pointer_impl<const _Tp>
- {
- public:
- typedef const _Tp element_type;
-
- const _Tp*
- get() const
- {
- if (_M_diff == 1)
- return 0;
- else
- return reinterpret_cast<const _Tp*>
- (reinterpret_cast<_UIntPtrType>(this) + _M_diff);
- }
-
- void
- set(const _Tp* __arg)
- {
- if (!__arg)
- _M_diff = 1;
- else
- _M_diff = reinterpret_cast<_UIntPtrType>(__arg)
- - reinterpret_cast<_UIntPtrType>(this);
- }
-
-
- inline bool
- operator<(const _Relative_pointer_impl& __rarg) const
- { return (reinterpret_cast<_UIntPtrType>(this->get())
- < reinterpret_cast<_UIntPtrType>(__rarg.get())); }
- inline bool
- operator==(const _Relative_pointer_impl& __rarg) const
- { return (reinterpret_cast<_UIntPtrType>(this->get())
- == reinterpret_cast<_UIntPtrType>(__rarg.get())); }
-
- private:
- #ifdef _GLIBCXX_USE_LONG_LONG
- typedef __gnu_cxx::__conditional_type<
- (sizeof(unsigned long) >= sizeof(void*)),
- unsigned long, unsigned long long>::__type _UIntPtrType;
- #else
- typedef unsigned long _UIntPtrType;
- #endif
- _UIntPtrType _M_diff;
- };
-
- struct _Invalid_type { };
-
- template<typename _Tp>
- struct _Reference_type
- { typedef _Tp& reference; };
- template<>
- struct _Reference_type<void>
- { typedef _Invalid_type& reference; };
- template<>
- struct _Reference_type<const void>
- { typedef const _Invalid_type& reference; };
- template<>
- struct _Reference_type<volatile void>
- { typedef volatile _Invalid_type& reference; };
- template<>
- struct _Reference_type<volatile const void>
- { typedef const volatile _Invalid_type& reference; };
-
- template<typename _Tp>
- struct _Unqualified_type
- { typedef _Tp type; };
-
- template<typename _Tp>
- struct _Unqualified_type<const _Tp>
- { typedef _Tp type; };
-
-
- template<typename _Storage_policy>
- class _Pointer_adapter : public _Storage_policy
- {
- public:
- typedef typename _Storage_policy::element_type element_type;
-
- typedef std::random_access_iterator_tag iterator_category;
- typedef typename _Unqualified_type<element_type>::type value_type;
- typedef std::ptrdiff_t difference_type;
- typedef _Pointer_adapter pointer;
- typedef typename _Reference_type<element_type>::reference reference;
-
-
-
-
- _Pointer_adapter(element_type* __arg = 0)
- { _Storage_policy::set(__arg); }
-
- _Pointer_adapter(const _Pointer_adapter& __arg)
- { _Storage_policy::set(__arg.get()); }
-
- template<typename _Up>
- _Pointer_adapter(_Up* __arg)
- { _Storage_policy::set(__arg); }
-
-
- template<typename _Up>
- _Pointer_adapter(const _Pointer_adapter<_Up>& __arg)
- { _Storage_policy::set(__arg.get()); }
-
- ~_Pointer_adapter() { }
-
-
- _Pointer_adapter&
- operator=(const _Pointer_adapter& __arg)
- {
- _Storage_policy::set(__arg.get());
- return *this;
- }
- template<typename _Up>
- _Pointer_adapter&
- operator=(const _Pointer_adapter<_Up>& __arg)
- {
- _Storage_policy::set(__arg.get());
- return *this;
- }
- template<typename _Up>
- _Pointer_adapter&
- operator=(_Up* __arg)
- {
- _Storage_policy::set(__arg);
- return *this;
- }
-
- inline reference
- operator*() const
- { return *(_Storage_policy::get()); }
-
- inline element_type*
- operator->() const
- { return _Storage_policy::get(); }
-
- inline reference
- operator[](std::ptrdiff_t __index) const
- { return _Storage_policy::get()[__index]; }
-
- private:
- typedef element_type*(_Pointer_adapter::*__unspecified_bool_type)() const;
- public:
- operator __unspecified_bool_type() const
- {
- return _Storage_policy::get() == 0 ? 0 :
- &_Pointer_adapter::operator->;
- }
-
- inline bool
- operator!() const
- { return (_Storage_policy::get() == 0); }
-
-
- inline friend std::ptrdiff_t
- operator-(const _Pointer_adapter& __lhs, element_type* __rhs)
- { return (__lhs.get() - __rhs); }
-
- inline friend std::ptrdiff_t
- operator-(element_type* __lhs, const _Pointer_adapter& __rhs)
- { return (__lhs - __rhs.get()); }
-
- template<typename _Up>
- inline friend std::ptrdiff_t
- operator-(const _Pointer_adapter& __lhs, _Up* __rhs)
- { return (__lhs.get() - __rhs); }
-
- template<typename _Up>
- inline friend std::ptrdiff_t
- operator-(_Up* __lhs, const _Pointer_adapter& __rhs)
- { return (__lhs - __rhs.get()); }
- template<typename _Up>
- inline std::ptrdiff_t
- operator-(const _Pointer_adapter<_Up>& __rhs) const
- { return (_Storage_policy::get() - __rhs.get()); }
-
-
-
-
-
-
-
- #define _CXX_POINTER_ARITH_OPERATOR_SET(INT_TYPE) \
- inline friend _Pointer_adapter \
- operator+(const _Pointer_adapter& __lhs, INT_TYPE __offset) \
- { return _Pointer_adapter(__lhs.get() + __offset); } \
- \
- inline friend _Pointer_adapter \
- operator+(INT_TYPE __offset, const _Pointer_adapter& __rhs) \
- { return _Pointer_adapter(__rhs.get() + __offset); } \
- \
- inline friend _Pointer_adapter \
- operator-(const _Pointer_adapter& __lhs, INT_TYPE __offset) \
- { return _Pointer_adapter(__lhs.get() - __offset); } \
- \
- inline _Pointer_adapter& \
- operator+=(INT_TYPE __offset) \
- { \
- _Storage_policy::set(_Storage_policy::get() + __offset); \
- return *this; \
- } \
- \
- inline _Pointer_adapter& \
- operator-=(INT_TYPE __offset) \
- { \
- _Storage_policy::set(_Storage_policy::get() - __offset); \
- return *this; \
- } \
-
-
- _CXX_POINTER_ARITH_OPERATOR_SET(short);
- _CXX_POINTER_ARITH_OPERATOR_SET(unsigned short);
- _CXX_POINTER_ARITH_OPERATOR_SET(int);
- _CXX_POINTER_ARITH_OPERATOR_SET(unsigned int);
- _CXX_POINTER_ARITH_OPERATOR_SET(long);
- _CXX_POINTER_ARITH_OPERATOR_SET(unsigned long);
-
- inline _Pointer_adapter&
- operator++()
- {
- _Storage_policy::set(_Storage_policy::get() + 1);
- return *this;
- }
-
- inline _Pointer_adapter
- operator++(int)
- {
- _Pointer_adapter tmp(*this);
- _Storage_policy::set(_Storage_policy::get() + 1);
- return tmp;
- }
-
- inline _Pointer_adapter&
- operator--()
- {
- _Storage_policy::set(_Storage_policy::get() - 1);
- return *this;
- }
-
- inline _Pointer_adapter
- operator--(int)
- {
- _Pointer_adapter tmp(*this);
- _Storage_policy::set(_Storage_policy::get() - 1);
- return tmp;
- }
-
- };
- #define _GCC_CXX_POINTER_COMPARISON_OPERATION_SET(OPERATOR) \
- template<typename _Tp1, typename _Tp2> \
- inline bool \
- operator OPERATOR(const _Pointer_adapter<_Tp1>& __lhs, _Tp2 __rhs) \
- { return __lhs.get() OPERATOR __rhs; } \
- \
- template<typename _Tp1, typename _Tp2> \
- inline bool \
- operator OPERATOR(_Tp1 __lhs, const _Pointer_adapter<_Tp2>& __rhs) \
- { return __lhs OPERATOR __rhs.get(); } \
- \
- template<typename _Tp1, typename _Tp2> \
- inline bool \
- operator OPERATOR(const _Pointer_adapter<_Tp1>& __lhs, \
- const _Pointer_adapter<_Tp2>& __rhs) \
- { return __lhs.get() OPERATOR __rhs.get(); } \
- \
-
-
- _GCC_CXX_POINTER_COMPARISON_OPERATION_SET(==)
- _GCC_CXX_POINTER_COMPARISON_OPERATION_SET(!=)
- _GCC_CXX_POINTER_COMPARISON_OPERATION_SET(<)
- _GCC_CXX_POINTER_COMPARISON_OPERATION_SET(<=)
- _GCC_CXX_POINTER_COMPARISON_OPERATION_SET(>)
- _GCC_CXX_POINTER_COMPARISON_OPERATION_SET(>=)
-
- template<typename _Tp>
- inline bool
- operator==(const _Pointer_adapter<_Tp>& __lhs, int __rhs)
- { return __lhs.get() == reinterpret_cast<void*>(__rhs); }
- template<typename _Tp>
- inline bool
- operator==(int __lhs, const _Pointer_adapter<_Tp>& __rhs)
- { return __rhs.get() == reinterpret_cast<void*>(__lhs); }
- template<typename _Tp>
- inline bool
- operator!=(const _Pointer_adapter<_Tp>& __lhs, int __rhs)
- { return __lhs.get() != reinterpret_cast<void*>(__rhs); }
- template<typename _Tp>
- inline bool
- operator!=(int __lhs, const _Pointer_adapter<_Tp>& __rhs)
- { return __rhs.get() != reinterpret_cast<void*>(__lhs); }
-
- template<typename _Tp>
- inline bool
- operator==(const _Pointer_adapter<_Tp>& __lhs,
- const _Pointer_adapter<_Tp>& __rhs)
- { return __lhs._Tp::operator==(__rhs); }
- template<typename _Tp>
- inline bool
- operator<=(const _Pointer_adapter<_Tp>& __lhs,
- const _Pointer_adapter<_Tp>& __rhs)
- { return __lhs._Tp::operator<(__rhs) || __lhs._Tp::operator==(__rhs); }
- template<typename _Tp>
- inline bool
- operator!=(const _Pointer_adapter<_Tp>& __lhs,
- const _Pointer_adapter<_Tp>& __rhs)
- { return !(__lhs._Tp::operator==(__rhs)); }
- template<typename _Tp>
- inline bool
- operator>(const _Pointer_adapter<_Tp>& __lhs,
- const _Pointer_adapter<_Tp>& __rhs)
- { return !(__lhs._Tp::operator<(__rhs) || __lhs._Tp::operator==(__rhs)); }
- template<typename _Tp>
- inline bool
- operator>=(const _Pointer_adapter<_Tp>& __lhs,
- const _Pointer_adapter<_Tp>& __rhs)
- { return !(__lhs._Tp::operator<(__rhs)); }
- template<typename _CharT, typename _Traits, typename _StoreT>
- inline std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const _Pointer_adapter<_StoreT>& __p)
- { return (__os << __p.get()); }
- _GLIBCXX_END_NAMESPACE_VERSION
- }
- #if __cplusplus >= 201103L
- namespace std _GLIBCXX_VISIBILITY(default)
- {
- _GLIBCXX_BEGIN_NAMESPACE_VERSION
- template<typename _Storage_policy>
- struct pointer_traits<__gnu_cxx::_Pointer_adapter<_Storage_policy>>
- {
-
- typedef __gnu_cxx::_Pointer_adapter<_Storage_policy> pointer;
-
- typedef typename pointer::element_type element_type;
-
- typedef typename pointer::difference_type difference_type;
- template<typename _Up>
- using rebind = typename __gnu_cxx::_Pointer_adapter<
- typename pointer_traits<_Storage_policy>::template rebind<_Up>>;
- static pointer pointer_to(typename pointer::reference __r) noexcept
- { return pointer(std::addressof(__r)); }
- };
- _GLIBCXX_END_NAMESPACE_VERSION
- }
- #endif
- #endif
|