Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef _EXTPTR_ALLOCATOR_H
00037 #define _EXTPTR_ALLOCATOR_H 1
00038
00039 #include <memory>
00040 #include <limits>
00041 #include <ext/pointer.h>
00042
00043 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
00044 {
00045 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 template<typename _Tp>
00056 class _ExtPtr_allocator
00057 {
00058 public:
00059 typedef std::size_t size_type;
00060 typedef std::ptrdiff_t difference_type;
00061
00062
00063 typedef _Pointer_adapter<_Relative_pointer_impl<_Tp> > pointer;
00064 typedef _Pointer_adapter<_Relative_pointer_impl<const _Tp> >
00065 const_pointer;
00066
00067 typedef _Tp& reference;
00068 typedef const _Tp& const_reference;
00069 typedef _Tp value_type;
00070
00071 template<typename _Up>
00072 struct rebind
00073 { typedef _ExtPtr_allocator<_Up> other; };
00074
00075 _ExtPtr_allocator() throw()
00076 : _M_real_alloc() { }
00077
00078 _ExtPtr_allocator(const _ExtPtr_allocator &__rarg) throw()
00079 : _M_real_alloc(__rarg._M_real_alloc) { }
00080
00081 template<typename _Up>
00082 _ExtPtr_allocator(const _ExtPtr_allocator<_Up>& __rarg) throw()
00083 : _M_real_alloc(__rarg._M_getUnderlyingImp()) { }
00084
00085 ~_ExtPtr_allocator() throw()
00086 { }
00087
00088 pointer address(reference __x) const
00089 { return std::__addressof(__x); }
00090
00091 const_pointer address(const_reference __x) const
00092 { return std::__addressof(__x); }
00093
00094 pointer allocate(size_type __n, void* __hint = 0)
00095 { return _M_real_alloc.allocate(__n,__hint); }
00096
00097 void deallocate(pointer __p, size_type __n)
00098 { _M_real_alloc.deallocate(__p.get(), __n); }
00099
00100 size_type max_size() const throw()
00101 { return std::numeric_limits<size_type>::max() / sizeof(_Tp); }
00102
00103 void construct(pointer __p, const _Tp& __val)
00104 { ::new(__p.get()) _Tp(__val); }
00105
00106 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00107 template<typename... _Args>
00108 void
00109 construct(pointer __p, _Args&&... __args)
00110 { ::new(__p.get()) _Tp(std::forward<_Args>(__args)...); }
00111 #endif
00112
00113 void destroy(pointer __p)
00114 { __p->~_Tp(); }
00115
00116 template<typename _Up>
00117 inline bool
00118 operator==(const _ExtPtr_allocator<_Up>& __rarg)
00119 { return _M_real_alloc == __rarg._M_getUnderlyingImp(); }
00120
00121 inline bool
00122 operator==(const _ExtPtr_allocator& __rarg)
00123 { return _M_real_alloc == __rarg._M_real_alloc; }
00124
00125 template<typename _Up>
00126 inline bool
00127 operator!=(const _ExtPtr_allocator<_Up>& __rarg)
00128 { return _M_real_alloc != __rarg._M_getUnderlyingImp(); }
00129
00130 inline bool
00131 operator!=(const _ExtPtr_allocator& __rarg)
00132 { return _M_real_alloc != __rarg._M_real_alloc; }
00133
00134 template<typename _Up>
00135 inline friend void
00136 swap(_ExtPtr_allocator<_Up>&, _ExtPtr_allocator<_Up>&);
00137
00138
00139 const std::allocator<_Tp>&
00140 _M_getUnderlyingImp() const
00141 { return _M_real_alloc; }
00142
00143 private:
00144 std::allocator<_Tp> _M_real_alloc;
00145 };
00146
00147
00148 template<>
00149 class _ExtPtr_allocator<void>
00150 {
00151 public:
00152 typedef std::size_t size_type;
00153 typedef std::ptrdiff_t difference_type;
00154 typedef void value_type;
00155
00156
00157 typedef _Pointer_adapter<_Relative_pointer_impl<void> > pointer;
00158 typedef _Pointer_adapter<_Relative_pointer_impl<const void> >
00159 const_pointer;
00160
00161 template<typename _Up>
00162 struct rebind
00163 { typedef _ExtPtr_allocator<_Up> other; };
00164
00165 private:
00166 std::allocator<void> _M_real_alloc;
00167 };
00168
00169 template<typename _Tp>
00170 inline void
00171 swap(_ExtPtr_allocator<_Tp>& __larg, _ExtPtr_allocator<_Tp>& __rarg)
00172 {
00173 std::allocator<_Tp> __tmp( __rarg._M_real_alloc );
00174 __rarg._M_real_alloc = __larg._M_real_alloc;
00175 __larg._M_real_alloc = __tmp;
00176 }
00177
00178 _GLIBCXX_END_NAMESPACE_VERSION
00179 }
00180
00181 #endif