1 template<class _Tp, class _Alloc>
3 typedef _Alloc __alloc_type;
5 typedef typename _Alloc::value_type __alloc_value_type;
6 typedef _Tp value_type;
7 static size_t _STLP_CALL __chunk(size_t __n) {
8 return (sizeof(__alloc_value_type)==sizeof(value_type)) ? __n :
9 ((__n*sizeof(value_type)+sizeof(__alloc_value_type)-1)/sizeof(__alloc_value_type));
11 static _Tp* _STLP_CALL allocate(size_t __n) { return 0 == __n ? 0 : (_Tp*) __alloc_type::allocate(__chunk(__n)); }
12 static void _STLP_CALL deallocate(_Tp * __p, size_t __n) {
13 __alloc_type::deallocate((__alloc_value_type*)__p, __chunk(__n)); }
16 // Allocator adaptor to turn an SGI-style allocator (e.g. alloc, malloc_alloc)
17 // into a standard-conforming allocator. Note that this adaptor does
18 // *not* assume that all objects of the underlying alloc class are
19 // identical, nor does it assume that all of the underlying alloc's
20 // member functions are static member functions. Note, also, that
21 // __allocator<_Tp, alloc> is essentially the same thing as allocator<_Tp>.
23 template <class _Tp, class _Alloc>
24 struct __allocator : public _Alloc {
25 typedef _Alloc __underlying_alloc;
27 typedef size_t size_type;
28 typedef ptrdiff_t difference_type;
30 typedef const _Tp* const_pointer;
31 typedef _Tp& reference;
32 typedef const _Tp& const_reference;
33 typedef _Tp value_type;
35 # if defined (_STLP_MEMBER_TEMPLATE_CLASSES)
36 template <class _Tp1> struct rebind {
37 typedef __allocator<_Tp1, _Alloc> other;
40 __allocator() _STLP_NOTHROW {}
41 __allocator(const _Alloc& ) _STLP_NOTHROW {}
42 __allocator(const __allocator<_Tp, _Alloc>& __a) _STLP_NOTHROW
44 # if defined (_STLP_MEMBER_TEMPLATES) && defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
46 __allocator(const __allocator<_Tp1, _Alloc>& __a) _STLP_NOTHROW
49 # ifdef _STLP_TRIVIAL_DESTRUCTOR_BUG
50 ~__allocator() _STLP_NOTHROW {}
52 pointer address(reference __x) const { return &__x; }
54 # if !defined (__WATCOM_CPLUSPLUS__)
55 const_pointer address(const_reference __x) const { return &__x; }
58 // __n is permitted to be 0.
59 _Tp* allocate(size_type __n, const void* = 0) {
63 ? __STATIC_CAST(_Tp*,__underlying_alloc::allocate(__n * sizeof(_Tp)))
67 // __p is not permitted to be a null pointer.
68 void deallocate(pointer __p, size_type __n)
69 { if (__p) __underlying_alloc::deallocate(__p, __n * sizeof(_Tp)); }
71 size_type max_size() const _STLP_NOTHROW
72 { return size_t(-1) / sizeof(_Tp); }
74 void construct(pointer __p, const_reference __val) { _STLP_STD::_Copy_Construct(__p, __val); }
75 void destroy(pointer __p) { _STLP_STD::_Destroy(__p); }
77 const __underlying_alloc& __get_underlying_alloc() const { return *this; }
80 #ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
81 template <class _Alloc>
82 class __allocator<void, _Alloc> {
83 typedef size_t size_type;
84 typedef ptrdiff_t difference_type;
85 typedef void* pointer;
86 typedef const void* const_pointer;
87 typedef void value_type;
88 #ifdef _STLP_MEMBER_TEMPLATE_CLASSES
89 template <class _Tp1> struct rebind {
90 typedef __allocator<_Tp1, _Alloc> other;
96 template <class _Tp, class _Alloc>
97 inline bool _STLP_CALL operator==(const __allocator<_Tp, _Alloc>& __a1,
98 const __allocator<_Tp, _Alloc>& __a2)
100 return __a1.__get_underlying_alloc() == __a2.__get_underlying_alloc();
103 #ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
104 template <class _Tp, class _Alloc>
105 inline bool _STLP_CALL operator!=(const __allocator<_Tp, _Alloc>& __a1,
106 const __allocator<_Tp, _Alloc>& __a2)
108 return __a1.__get_underlying_alloc() != __a2.__get_underlying_alloc();
110 #endif /* _STLP_FUNCTION_TMPL_PARTIAL_ORDER */
113 // Comparison operators for all of the predifined SGI-style allocators.
114 // This ensures that __allocator<malloc_alloc> (for example) will
117 #ifndef _STLP_NON_TYPE_TMPL_PARAM_BUG
118 inline bool _STLP_CALL operator==(const __malloc_alloc&, const __malloc_alloc&)
121 # ifdef _STLP_FUNCTION_TMPL_PARTIAL_ORDER
122 inline bool _STLP_CALL operator!=(const __malloc_alloc&, const __malloc_alloc&)
126 inline bool _STLP_CALL operator==(const __new_alloc&, const __new_alloc&) { return true; }
128 # ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
129 inline bool _STLP_CALL operator!=(const __new_alloc&, const __new_alloc&) { return false; }
132 # if !defined (_STLP_USE_NO_IOSTREAMS)
133 inline bool _STLP_CALL operator==(const __node_alloc&,
137 # if defined( _STLP_FUNCTION_TMPL_PARTIAL_ORDER )
139 inline bool _STLP_CALL operator!=(const __node_alloc&,
145 #endif /* _STLP_NON_TYPE_TMPL_PARAM_BUG */
147 template <class _Alloc>
148 inline bool _STLP_CALL operator==(const __debug_alloc<_Alloc>&, const __debug_alloc<_Alloc>&) { return true; }
149 # ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
150 template <class _Alloc>
151 inline bool _STLP_CALL operator!=(const __debug_alloc<_Alloc>&, const __debug_alloc<_Alloc>&) { return false; }
154 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
156 // Versions for the predefined SGI-style allocators.
158 struct _Alloc_traits<_Tp, __malloc_alloc> {
159 typedef __allocator<_Tp, __malloc_alloc> allocator_type;
162 # if !defined (_STLP_USE_NO_IOSTREAMS)
164 struct _Alloc_traits<_Tp, __node_alloc> {
165 typedef __allocator<_Tp, __node_alloc> allocator_type;
169 template <class _Tp, class _Alloc>
170 struct _Alloc_traits<_Tp, __debug_alloc<_Alloc> > {
171 typedef __allocator<_Tp, __debug_alloc<_Alloc> > allocator_type;
174 // Versions for the __allocator adaptor used with the predefined
175 // SGI-style allocators.
177 template <class _Tp, class _Tp1, class _Alloc>
178 struct _Alloc_traits<_Tp, __allocator<_Tp1, _Alloc > > {
179 typedef __allocator<_Tp, _Alloc > allocator_type;
184 #if defined (_STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE)
186 // Versions for the predefined SGI-style allocators.
189 # if defined (_STLP_NON_TYPE_TMPL_PARAM_BUG)
191 typedef __malloc_alloc __malloc_alloc_dfl;
194 inline __allocator<_Tp, __malloc_alloc_dfl >& _STLP_CALL
195 __stl_alloc_rebind(__malloc_alloc_dfl& __a, const _Tp*) {
196 return (__allocator<_Tp, __malloc_alloc_dfl >&)__a;
199 # if !defined (_STLP_USE_NO_IOSTREAMS)
201 inline __allocator<_Tp, __node_alloc>& _STLP_CALL
202 __stl_alloc_rebind(__node_alloc& __a, const _Tp*) {
203 return (__allocator<_Tp, __node_alloc>&)__a;
208 inline __allocator<_Tp, __malloc_alloc_dfl > _STLP_CALL
209 __stl_alloc_create(const __malloc_alloc_dfl&, const _Tp*) {
210 return __allocator<_Tp, __malloc_alloc_dfl > ();
213 # if !defined (_STLP_USE_NO_IOSTREAMS)
215 inline __allocator<_Tp, __node_alloc> _STLP_CALL
216 __stl_alloc_create(const __node_alloc&, const _Tp*) {
217 return __allocator<_Tp, __node_alloc>();
225 inline __allocator<_Tp, __malloc_alloc>& _STLP_CALL
226 __stl_alloc_rebind(__malloc_alloc& __a, const _Tp*) {
227 return (__allocator<_Tp, __malloc_alloc>&)__a;
230 # if !defined (_STLP_USE_NO_IOSTREAMS)
232 inline __allocator<_Tp, __node_alloc>& _STLP_CALL
233 __stl_alloc_rebind(__node_alloc& __a, const _Tp*) {
234 return (__allocator<_Tp, __node_alloc>&)__a;
239 inline __allocator<_Tp, __malloc_alloc> _STLP_CALL
240 __stl_alloc_create(const __malloc_alloc&, const _Tp*) {
241 return __allocator<_Tp, __malloc_alloc>();
244 # if !defined (_STLP_USE_NO_IOSTREAMS)
246 inline __allocator<_Tp, __node_alloc> _STLP_CALL
247 __stl_alloc_create(const __node_alloc&, const _Tp*) {
248 return __allocator<_Tp, __node_alloc>();
254 template <class _Tp, class _Alloc>
255 inline __allocator<_Tp, __debug_alloc<_Alloc> > _STLP_CALL
256 __stl_alloc_create(const __debug_alloc<_Alloc>&, const _Tp*) {
257 return __allocator<_Tp, __debug_alloc<_Alloc> >();
259 template <class _Tp, class _Alloc>
260 inline __allocator<_Tp, __debug_alloc<_Alloc> >& _STLP_CALL
261 __stl_alloc_rebind(__debug_alloc<_Alloc>& __a, const _Tp*) {
262 return (__allocator<_Tp, __debug_alloc<_Alloc> >&)__a;
266 inline __allocator<_Tp, __new_alloc > _STLP_CALL
267 __stl_alloc_create(const __new_alloc&, const _Tp*) {
268 return __allocator<_Tp, __new_alloc >();
271 inline __allocator<_Tp, __new_alloc >& _STLP_CALL
272 __stl_alloc_rebind(__new_alloc& __a, const _Tp*) {
273 return (__allocator<_Tp, __new_alloc >&)__a;
276 template <class _Tp1, class _Alloc, class _Tp2>
277 inline __allocator<_Tp2, _Alloc>& _STLP_CALL
278 __stl_alloc_rebind(__allocator<_Tp1, _Alloc>& __a, const _Tp2*) {
279 return (__allocator<_Tp2, _Alloc>&)__a;
282 template <class _Tp1, class _Alloc, class _Tp2>
283 inline __allocator<_Tp2, _Alloc> _STLP_CALL
284 __stl_alloc_create(const __allocator<_Tp1, _Alloc>&, const _Tp2*) {
285 return __allocator<_Tp2, _Alloc>();