_alloc.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. /*
  2. *
  3. * Copyright (c) 1996,1997
  4. * Silicon Graphics Computer Systems, Inc.
  5. *
  6. * Copyright (c) 1997
  7. * Moscow Center for SPARC Technology
  8. *
  9. * Copyright (c) 1999
  10. * Boris Fomitchev
  11. *
  12. * This material is provided "as is", with absolutely no warranty expressed
  13. * or implied. Any use is at your own risk.
  14. *
  15. * Permission to use or copy this software for any purpose is hereby granted
  16. * without fee, provided the above notices are retained on all copies.
  17. * Permission to modify the code and to distribute modified code is granted,
  18. * provided the above notices are retained, and a notice that the code was
  19. * modified is included with the above copyright notice.
  20. *
  21. */
  22. /* NOTE: This is an internal header file, included by other STL headers.
  23. * You should not attempt to use it directly.
  24. */
  25. #ifndef _STLP_INTERNAL_ALLOC_H
  26. #define _STLP_INTERNAL_ALLOC_H
  27. #ifndef _STLP_INTERNAL_CSTDDEF
  28. # include <stl/_cstddef.h>
  29. #endif
  30. #ifndef _STLP_INTERNAL_CSTDLIB
  31. # include <stl/_cstdlib.h>
  32. #endif
  33. #ifndef _STLP_INTERNAL_CSTRING
  34. # include <stl/_cstring.h>
  35. #endif
  36. #ifndef _STLP_INTERNAL_ALGOBASE_H
  37. # include <stl/_algobase.h>
  38. #endif
  39. #ifndef _STLP_INTERNAL_NEW_HEADER
  40. # include <stl/_new.h>
  41. #endif
  42. #ifndef _STLP_INTERNAL_CONSTRUCT_H
  43. # include <stl/_construct.h>
  44. #endif
  45. _STLP_BEGIN_NAMESPACE
  46. // Malloc-based allocator. Typically slower than default alloc below.
  47. // Typically thread-safe and more storage efficient.
  48. #if !defined (_STLP_USE_NO_IOSTREAMS)
  49. typedef void (* __oom_handler_type)();
  50. #endif
  51. class _STLP_CLASS_DECLSPEC __malloc_alloc {
  52. public:
  53. // this one is needed for proper simple_alloc wrapping
  54. typedef char value_type;
  55. static void* _STLP_CALL allocate(size_t __n)
  56. #if !defined (_STLP_USE_NO_IOSTREAMS)
  57. ;
  58. #else
  59. {
  60. void *__result = malloc(__n);
  61. if (__result == 0) {
  62. _STLP_THROW_BAD_ALLOC;
  63. }
  64. return __result;
  65. }
  66. #endif
  67. static void _STLP_CALL deallocate(void* __p, size_t /* __n */) { free((char*)__p); }
  68. #if !defined (_STLP_USE_NO_IOSTREAMS)
  69. static __oom_handler_type _STLP_CALL set_malloc_handler(__oom_handler_type __f);
  70. #endif
  71. };
  72. // New-based allocator. Typically slower than default alloc below.
  73. // Typically thread-safe and more storage efficient.
  74. class _STLP_CLASS_DECLSPEC __new_alloc {
  75. public:
  76. // this one is needed for proper simple_alloc wrapping
  77. typedef char value_type;
  78. static void* _STLP_CALL allocate(size_t __n) { return __stl_new(__n); }
  79. static void _STLP_CALL deallocate(void* __p, size_t) { __stl_delete(__p); }
  80. };
  81. // Allocator adaptor to check size arguments for debugging.
  82. // Reports errors using assert. Checking can be disabled with
  83. // NDEBUG, but it's far better to just use the underlying allocator
  84. // instead when no checking is desired.
  85. // There is some evidence that this can confuse Purify.
  86. // This adaptor can only be applied to raw allocators
  87. template <class _Alloc>
  88. class __debug_alloc : public _Alloc {
  89. public:
  90. typedef _Alloc __allocator_type;
  91. typedef typename _Alloc::value_type value_type;
  92. private:
  93. struct __alloc_header {
  94. size_t __magic: 16;
  95. size_t __type_size:16;
  96. _STLP_UINT32_T _M_size;
  97. }; // that is 8 bytes for sure
  98. // Sunpro CC has bug on enums, so extra_before/after set explicitly
  99. enum { __pad = 8, __magic = 0xdeba, __deleted_magic = 0xdebd,
  100. __shred_byte = _STLP_SHRED_BYTE };
  101. enum { __extra_before = 16, __extra_after = 8 };
  102. // Size of space used to store size. Note
  103. // that this must be large enough to preserve
  104. // alignment.
  105. static size_t _STLP_CALL __extra_before_chunk() {
  106. return (long)__extra_before / sizeof(value_type) +
  107. (size_t)((long)__extra_before % sizeof(value_type) > 0);
  108. }
  109. static size_t _STLP_CALL __extra_after_chunk() {
  110. return (long)__extra_after / sizeof(value_type) +
  111. (size_t)((long)__extra_after % sizeof(value_type) > 0);
  112. }
  113. public:
  114. __debug_alloc() {}
  115. ~__debug_alloc() {}
  116. static void* _STLP_CALL allocate(size_t);
  117. static void _STLP_CALL deallocate(void *, size_t);
  118. };
  119. # if defined (__OS400__)
  120. // dums 02/05/2007: is it really necessary ?
  121. enum { _MAX_BYTES = 256 };
  122. # else
  123. enum { _MAX_BYTES = 32 * sizeof(void*) };
  124. # endif
  125. #if !defined (_STLP_USE_NO_IOSTREAMS)
  126. // Default node allocator.
  127. // With a reasonable compiler, this should be roughly as fast as the
  128. // original STL class-specific allocators, but with less fragmentation.
  129. class _STLP_CLASS_DECLSPEC __node_alloc {
  130. static void * _STLP_CALL _M_allocate(size_t& __n);
  131. /* __p may not be 0 */
  132. static void _STLP_CALL _M_deallocate(void *__p, size_t __n);
  133. public:
  134. // this one is needed for proper simple_alloc wrapping
  135. typedef char value_type;
  136. /* __n must be > 0 */
  137. static void* _STLP_CALL allocate(size_t& __n)
  138. { return (__n > (size_t)_MAX_BYTES) ? __stl_new(__n) : _M_allocate(__n); }
  139. /* __p may not be 0 */
  140. static void _STLP_CALL deallocate(void *__p, size_t __n)
  141. { if (__n > (size_t)_MAX_BYTES) __stl_delete(__p); else _M_deallocate(__p, __n); }
  142. };
  143. # if defined (_STLP_USE_TEMPLATE_EXPORT)
  144. _STLP_EXPORT_TEMPLATE_CLASS __debug_alloc<__node_alloc>;
  145. # endif
  146. #endif
  147. #if defined (_STLP_USE_TEMPLATE_EXPORT)
  148. _STLP_EXPORT_TEMPLATE_CLASS __debug_alloc<__new_alloc>;
  149. _STLP_EXPORT_TEMPLATE_CLASS __debug_alloc<__malloc_alloc>;
  150. #endif
  151. /* macro to convert the allocator for initialization
  152. * not using MEMBER_TEMPLATE_CLASSES as it should work given template constructor */
  153. #if defined (_STLP_MEMBER_TEMPLATES) || ! defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
  154. /* if _STLP_NO_TEMPLATE_CONVERSIONS is set, the member template constructor is
  155. * not used implicitly to convert allocator parameter, so let us do it explicitly */
  156. # if defined (_STLP_MEMBER_TEMPLATE_CLASSES) && defined (_STLP_NO_TEMPLATE_CONVERSIONS)
  157. # define _STLP_CONVERT_ALLOCATOR(__a, _Tp) __stl_alloc_create(__a,(_Tp*)0)
  158. # else
  159. # define _STLP_CONVERT_ALLOCATOR(__a, _Tp) __a
  160. # endif
  161. /* else convert, but only if partial specialization works, since else
  162. * Container::allocator_type won't be different */
  163. #else
  164. # define _STLP_CONVERT_ALLOCATOR(__a, _Tp) __stl_alloc_create(__a,(_Tp*)0)
  165. #endif
  166. // Another allocator adaptor: _Alloc_traits. This serves two
  167. // purposes. First, make it possible to write containers that can use
  168. // either SGI-style allocators or standard-conforming allocator.
  169. // The fully general version.
  170. template <class _Tp, class _Allocator>
  171. struct _Alloc_traits {
  172. typedef _Allocator _Orig;
  173. #if !defined (_STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE)
  174. typedef typename _Allocator::_STLP_TEMPLATE rebind<_Tp> _Rebind_type;
  175. typedef typename _Rebind_type::other allocator_type;
  176. static allocator_type create_allocator(const _Orig& __a)
  177. { return allocator_type(_STLP_CONVERT_ALLOCATOR(__a, _Tp)); }
  178. #else
  179. // this is not actually true, used only to pass this type through
  180. // to dynamic overload selection in _STLP_alloc_proxy methods
  181. typedef _Allocator allocator_type;
  182. #endif
  183. };
  184. #if defined (_STLP_USE_PERTHREAD_ALLOC)
  185. _STLP_END_NAMESPACE
  186. // include additional header here
  187. # include <stl/_pthread_alloc.h>
  188. _STLP_BEGIN_NAMESPACE
  189. typedef __pthread_alloc __alloc_type;
  190. #elif defined (_STLP_USE_NEWALLOC)
  191. typedef __new_alloc __alloc_type;
  192. #elif defined (_STLP_USE_MALLOC)
  193. typedef __malloc_alloc __alloc_type;
  194. #else
  195. typedef __node_alloc __alloc_type;
  196. #endif
  197. #if defined (_STLP_DEBUG_ALLOC)
  198. typedef __debug_alloc<__alloc_type> __sgi_alloc;
  199. #else
  200. typedef __alloc_type __sgi_alloc;
  201. #endif
  202. #if !defined (_STLP_NO_ANACHRONISMS)
  203. typedef __sgi_alloc __single_client_alloc;
  204. typedef __sgi_alloc __multithreaded_alloc;
  205. #endif
  206. // This implements allocators as specified in the C++ standard.
  207. //
  208. // Note that standard-conforming allocators use many language features
  209. // that are not yet widely implemented. In particular, they rely on
  210. // member templates, partial specialization, partial ordering of function
  211. // templates, the typename keyword, and the use of the template keyword
  212. // to refer to a template member of a dependent type.
  213. /*
  214. template <class _Tp>
  215. struct _AllocatorAux {
  216. typedef _Tp* pointer;
  217. typedef const _Tp* const_pointer;
  218. typedef _Tp& reference;
  219. typedef const _Tp& const_reference;
  220. pointer address(reference __x) const {return &__x;}
  221. const_pointer address(const_reference __x) const { return &__x; }
  222. };
  223. template <class _Tp>
  224. struct _AllocatorAux<const _Tp> {
  225. typedef _Tp* pointer;
  226. typedef const _Tp* const_pointer;
  227. typedef _Tp& reference;
  228. typedef const _Tp& const_reference;
  229. const_pointer address(const_reference __x) const { return &__x; }
  230. };
  231. */
  232. template <class _Tp>
  233. class allocator //: public _AllocatorAux<_Tp>
  234. /* A small helper struct to recognize STLport allocator implementation
  235. * from any user specialization one.
  236. */
  237. : public __stlport_class<allocator<_Tp> >
  238. {
  239. public:
  240. typedef _Tp value_type;
  241. typedef _Tp* pointer;
  242. typedef const _Tp* const_pointer;
  243. typedef _Tp& reference;
  244. typedef const _Tp& const_reference;
  245. typedef size_t size_type;
  246. typedef ptrdiff_t difference_type;
  247. #if defined (_STLP_MEMBER_TEMPLATE_CLASSES)
  248. template <class _Tp1> struct rebind {
  249. typedef allocator<_Tp1> other;
  250. };
  251. #endif
  252. allocator() _STLP_NOTHROW {}
  253. #if defined (_STLP_MEMBER_TEMPLATES)
  254. template <class _Tp1> allocator(const allocator<_Tp1>&) _STLP_NOTHROW {}
  255. #endif
  256. allocator(const allocator<_Tp>&) _STLP_NOTHROW {}
  257. #if !defined (_STLP_NO_MOVE_SEMANTIC)
  258. allocator(__move_source<allocator<_Tp> > src) _STLP_NOTHROW { _STLP_MARK_PARAMETER_AS_UNUSED(&src); }
  259. #endif
  260. ~allocator() _STLP_NOTHROW {}
  261. pointer address(reference __x) const {return &__x;}
  262. const_pointer address(const_reference __x) const { return &__x; }
  263. // __n is permitted to be 0. The C++ standard says nothing about what the return value is when __n == 0.
  264. _Tp* allocate(size_type __n, const void* = 0) {
  265. if (__n > max_size()) {
  266. _STLP_THROW_BAD_ALLOC;
  267. }
  268. if (__n != 0) {
  269. size_type __buf_size = __n * sizeof(value_type);
  270. _Tp* __ret = __REINTERPRET_CAST(_Tp*, __sgi_alloc::allocate(__buf_size));
  271. #if defined (_STLP_DEBUG_UNINITIALIZED) && !defined (_STLP_DEBUG_ALLOC)
  272. memset((char*)__ret, _STLP_SHRED_BYTE, __buf_size);
  273. #endif
  274. return __ret;
  275. }
  276. return 0;
  277. }
  278. // __p is permitted to be a null pointer, only if n==0.
  279. void deallocate(pointer __p, size_type __n) {
  280. _STLP_ASSERT( (__p == 0) == (__n == 0) )
  281. if (__p != 0) {
  282. #if defined (_STLP_DEBUG_UNINITIALIZED) && !defined (_STLP_DEBUG_ALLOC)
  283. memset((char*)__p, _STLP_SHRED_BYTE, __n * sizeof(value_type));
  284. #endif
  285. __sgi_alloc::deallocate((void*)__p, __n * sizeof(value_type));
  286. }
  287. }
  288. #if !defined (_STLP_NO_ANACHRONISMS)
  289. // backwards compatibility
  290. void deallocate(pointer __p) const { if (__p != 0) __sgi_alloc::deallocate((void*)__p, sizeof(value_type)); }
  291. #endif
  292. size_type max_size() const _STLP_NOTHROW { return size_t(-1) / sizeof(value_type); }
  293. void construct(pointer __p, const_reference __val) { _STLP_STD::_Copy_Construct(__p, __val); }
  294. void destroy(pointer __p) { _STLP_STD::_Destroy(__p); }
  295. #if defined (_STLP_NO_EXTENSIONS)
  296. /* STLport extension giving rounded size of an allocated memory buffer
  297. * This method do not have to be part of a user defined allocator implementation
  298. * and won't even be called if such a function was granted.
  299. */
  300. protected:
  301. #endif
  302. _Tp* _M_allocate(size_type __n, size_type& __allocated_n) {
  303. if (__n > max_size()) {
  304. _STLP_THROW_BAD_ALLOC;
  305. }
  306. if (__n != 0) {
  307. size_type __buf_size = __n * sizeof(value_type);
  308. _Tp* __ret = __REINTERPRET_CAST(_Tp*, __sgi_alloc::allocate(__buf_size));
  309. #if defined (_STLP_DEBUG_UNINITIALIZED) && !defined (_STLP_DEBUG_ALLOC)
  310. memset((char*)__ret, _STLP_SHRED_BYTE, __buf_size);
  311. #endif
  312. __allocated_n = __buf_size / sizeof(value_type);
  313. return __ret;
  314. }
  315. return 0;
  316. }
  317. #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
  318. void _M_swap_workaround(allocator<_Tp>& __other) {}
  319. #endif
  320. };
  321. _STLP_TEMPLATE_NULL
  322. class _STLP_CLASS_DECLSPEC allocator<void> {
  323. public:
  324. typedef size_t size_type;
  325. typedef ptrdiff_t difference_type;
  326. typedef void* pointer;
  327. typedef const void* const_pointer;
  328. #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
  329. typedef void value_type;
  330. #endif
  331. #if defined (_STLP_MEMBER_TEMPLATE_CLASSES)
  332. template <class _Tp1> struct rebind {
  333. typedef allocator<_Tp1> other;
  334. };
  335. #endif
  336. };
  337. template <class _T1, class _T2>
  338. inline bool _STLP_CALL operator==(const allocator<_T1>&, const allocator<_T2>&) _STLP_NOTHROW
  339. { return true; }
  340. template <class _T1, class _T2>
  341. inline bool _STLP_CALL operator!=(const allocator<_T1>&, const allocator<_T2>&) _STLP_NOTHROW
  342. { return false; }
  343. #if defined (_STLP_USE_TEMPLATE_EXPORT)
  344. _STLP_EXPORT_TEMPLATE_CLASS allocator<char>;
  345. # if defined (_STLP_HAS_WCHAR_T)
  346. _STLP_EXPORT_TEMPLATE_CLASS allocator<wchar_t>;
  347. # endif
  348. # if defined (_STLP_USE_PTR_SPECIALIZATIONS)
  349. _STLP_EXPORT_TEMPLATE_CLASS allocator<void*>;
  350. # endif
  351. #endif
  352. _STLP_MOVE_TO_PRIV_NAMESPACE
  353. template <class _Tp>
  354. struct __alloc_type_traits {
  355. #if !defined (__BORLANDC__)
  356. typedef typename _IsSTLportClass<allocator<_Tp> >::_Ret _STLportAlloc;
  357. #else
  358. enum { _Is = _IsSTLportClass<allocator<_Tp> >::_Is };
  359. typedef typename __bool2type<_Is>::_Ret _STLportAlloc;
  360. #endif
  361. //The default allocator implementation which is recognize thanks to the
  362. //__stlport_class inheritance is a stateless object so:
  363. typedef _STLportAlloc has_trivial_default_constructor;
  364. typedef _STLportAlloc has_trivial_copy_constructor;
  365. typedef _STLportAlloc has_trivial_assignment_operator;
  366. typedef _STLportAlloc has_trivial_destructor;
  367. typedef _STLportAlloc is_POD_type;
  368. };
  369. _STLP_MOVE_TO_STD_NAMESPACE
  370. #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
  371. template <class _Tp>
  372. struct __type_traits<allocator<_Tp> > : _STLP_PRIV __alloc_type_traits<_Tp> {};
  373. #else
  374. _STLP_TEMPLATE_NULL
  375. struct __type_traits<allocator<char> > : _STLP_PRIV __alloc_type_traits<char> {};
  376. # if defined (_STLP_HAS_WCHAR_T)
  377. _STLP_TEMPLATE_NULL
  378. struct __type_traits<allocator<wchar_t> > : _STLP_PRIV __alloc_type_traits<wchar_t> {};
  379. # endif
  380. # if defined (_STLP_USE_PTR_SPECIALIZATIONS)
  381. _STLP_TEMPLATE_NULL
  382. struct __type_traits<allocator<void*> > : _STLP_PRIV __alloc_type_traits<void*> {};
  383. # endif
  384. #endif
  385. #if !defined (_STLP_FORCE_ALLOCATORS)
  386. # define _STLP_FORCE_ALLOCATORS(a,y)
  387. #endif
  388. #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && !defined (_STLP_MEMBER_TEMPLATE_CLASSES)
  389. // The version for the default allocator, for rare occasion when we have partial spec w/o member template classes
  390. template <class _Tp, class _Tp1>
  391. struct _Alloc_traits<_Tp, allocator<_Tp1> > {
  392. typedef allocator<_Tp1> _Orig;
  393. typedef allocator<_Tp> allocator_type;
  394. static allocator_type create_allocator(const allocator<_Tp1 >& __a)
  395. { return allocator_type(_STLP_CONVERT_ALLOCATOR(__a, _Tp)); }
  396. };
  397. #endif
  398. #if !defined (_STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE) && defined (_STLP_MEMBER_TEMPLATES)
  399. template <class _Tp, class _Alloc>
  400. inline _STLP_TYPENAME_ON_RETURN_TYPE _Alloc_traits<_Tp, _Alloc>::allocator_type _STLP_CALL
  401. __stl_alloc_create(const _Alloc& __a, const _Tp*) {
  402. typedef typename _Alloc::_STLP_TEMPLATE rebind<_Tp>::other _Rebound_type;
  403. return _Rebound_type(__a);
  404. }
  405. #else
  406. // If custom allocators are being used without member template classes support :
  407. // user (on purpose) is forced to define rebind/get operations !!!
  408. template <class _Tp1, class _Tp2>
  409. inline allocator<_Tp2>& _STLP_CALL
  410. __stl_alloc_rebind(allocator<_Tp1>& __a, const _Tp2*) { return (allocator<_Tp2>&)(__a); }
  411. template <class _Tp1, class _Tp2>
  412. inline allocator<_Tp2> _STLP_CALL
  413. __stl_alloc_create(const allocator<_Tp1>&, const _Tp2*) { return allocator<_Tp2>(); }
  414. #endif
  415. _STLP_MOVE_TO_PRIV_NAMESPACE
  416. // inheritance is being used for EBO optimization
  417. template <class _Value, class _Tp, class _MaybeReboundAlloc>
  418. class _STLP_alloc_proxy : public _MaybeReboundAlloc {
  419. private:
  420. typedef _MaybeReboundAlloc _Base;
  421. typedef typename _Base::size_type size_type;
  422. typedef _STLP_alloc_proxy<_Value, _Tp, _MaybeReboundAlloc> _Self;
  423. public:
  424. _Value _M_data;
  425. _STLP_alloc_proxy (const _MaybeReboundAlloc& __a, _Value __p) :
  426. _MaybeReboundAlloc(__a), _M_data(__p) {}
  427. #if !defined (_STLP_NO_MOVE_SEMANTIC)
  428. _STLP_alloc_proxy (__move_source<_Self> src) :
  429. _Base(_STLP_PRIV _AsMoveSource(src.get()._M_base())),
  430. _M_data(_STLP_PRIV _AsMoveSource(src.get()._M_data)) {}
  431. _Base& _M_base()
  432. { return *this; }
  433. #endif
  434. private:
  435. /* Following are helper methods to detect stateless allocators and avoid
  436. * swap in this case. For some compilers (VC6) it is a workaround for a
  437. * compiler bug in the Empty Base class Optimization feature, for others
  438. * it is a small optimization or nothing if no EBO. */
  439. void _M_swap_alloc(_Self&, const __true_type& /*_IsStateless*/)
  440. {}
  441. void _M_swap_alloc(_Self& __x, const __false_type& /*_IsStateless*/) {
  442. _MaybeReboundAlloc &__base_this = *this;
  443. _MaybeReboundAlloc &__base_x = __x;
  444. _STLP_STD::swap(__base_this, __base_x);
  445. }
  446. public:
  447. void _M_swap_alloc(_Self& __x) {
  448. #if !defined (__BORLANDC__)
  449. typedef typename _IsStateless<_MaybeReboundAlloc>::_Ret _StatelessAlloc;
  450. #else
  451. typedef typename __bool2type<_IsStateless<_MaybeReboundAlloc>::_Is>::_Ret _StatelessAlloc;
  452. #endif
  453. _M_swap_alloc(__x, _StatelessAlloc());
  454. }
  455. /* We need to define the following swap implementation for allocator with state
  456. * as those allocators might have implement a special swap function to correctly
  457. * move datas from an instance to the oher, _STLP_alloc_proxy should not break
  458. * this mecanism. */
  459. void swap(_Self& __x) {
  460. _M_swap_alloc(__x);
  461. _STLP_STD::swap(_M_data, __x._M_data);
  462. }
  463. _Tp* allocate(size_type __n, size_type& __allocated_n) {
  464. #if !defined (__BORLANDC__)
  465. typedef typename _IsSTLportClass<_MaybeReboundAlloc>::_Ret _STLportAlloc;
  466. #else
  467. typedef typename __bool2type<_IsSTLportClass<_MaybeReboundAlloc>::_Is>::_Ret _STLportAlloc;
  468. #endif
  469. return allocate(__n, __allocated_n, _STLportAlloc());
  470. }
  471. // Unified interface to perform allocate()/deallocate() with limited
  472. // language support
  473. #if defined (_STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE)
  474. // else it is rebound already, and allocate() member is accessible
  475. _Tp* allocate(size_type __n)
  476. { return __stl_alloc_rebind(__STATIC_CAST(_Base&, *this), __STATIC_CAST(_Tp*, 0)).allocate(__n, 0); }
  477. void deallocate(_Tp* __p, size_type __n)
  478. { __stl_alloc_rebind(__STATIC_CAST(_Base&, *this), __STATIC_CAST(_Tp*, 0)).deallocate(__p, __n); }
  479. private:
  480. _Tp* allocate(size_type __n, size_type& __allocated_n, const __true_type& /*STLport allocator*/)
  481. { return __stl_alloc_rebind(__STATIC_CAST(_Base&, *this), __STATIC_CAST(_Tp*, 0))._M_allocate(__n, __allocated_n); }
  482. #else
  483. //Expose Standard allocate overload (using expression do not work for some compilers (Borland))
  484. _Tp* allocate(size_type __n)
  485. { return _Base::allocate(__n); }
  486. private:
  487. _Tp* allocate(size_type __n, size_type& __allocated_n, const __true_type& /*STLport allocator*/)
  488. { return _Base::_M_allocate(__n, __allocated_n); }
  489. #endif
  490. _Tp* allocate(size_type __n, size_type& __allocated_n, const __false_type& /*STLport allocator*/)
  491. { __allocated_n = __n; return allocate(__n); }
  492. };
  493. #if defined (_STLP_USE_TEMPLATE_EXPORT)
  494. _STLP_EXPORT_TEMPLATE_CLASS _STLP_alloc_proxy<char*, char, allocator<char> >;
  495. # if defined (_STLP_HAS_WCHAR_T)
  496. _STLP_EXPORT_TEMPLATE_CLASS _STLP_alloc_proxy<wchar_t*, wchar_t, allocator<wchar_t> >;
  497. # endif
  498. # if defined (_STLP_USE_PTR_SPECIALIZATIONS)
  499. _STLP_EXPORT_TEMPLATE_CLASS _STLP_alloc_proxy<void**, void*, allocator<void*> >;
  500. # endif
  501. #endif
  502. _STLP_MOVE_TO_STD_NAMESPACE
  503. _STLP_END_NAMESPACE
  504. #if defined (_STLP_EXPOSE_GLOBALS_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
  505. # include <stl/_alloc.c>
  506. #endif
  507. #endif /* _STLP_INTERNAL_ALLOC_H */
  508. // Local Variables:
  509. // mode:C++
  510. // End: