epoc32/include/stdapis/stlport/stl/_alloc.h
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
     1.1 --- a/epoc32/include/stdapis/stlport/stl/_alloc.h	Tue Nov 24 13:55:44 2009 +0000
     1.2 +++ b/epoc32/include/stdapis/stlport/stl/_alloc.h	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -1,1 +1,543 @@
     1.4 -_alloc.h
     1.5 +/*
     1.6 + *
     1.7 + * Copyright (c) 1996,1997
     1.8 + * Silicon Graphics Computer Systems, Inc.
     1.9 + *
    1.10 + * Copyright (c) 1997
    1.11 + * Moscow Center for SPARC Technology
    1.12 + *
    1.13 + * Copyright (c) 1999 
    1.14 + * Boris Fomitchev
    1.15 + *
    1.16 + * This material is provided "as is", with absolutely no warranty expressed
    1.17 + * or implied. Any use is at your own risk.
    1.18 + *
    1.19 + * Permission to use or copy this software for any purpose is hereby granted 
    1.20 + * without fee, provided the above notices are retained on all copies.
    1.21 + * Permission to modify the code and to distribute modified code is granted,
    1.22 + * provided the above notices are retained, and a notice that the code was
    1.23 + * modified is included with the above copyright notice.
    1.24 + *
    1.25 + */
    1.26 +
    1.27 +/* NOTE: This is an internal header file, included by other STL headers.
    1.28 + *   You should not attempt to use it directly.
    1.29 + */
    1.30 +
    1.31 +#ifndef _STLP_INTERNAL_ALLOC_H
    1.32 +#define _STLP_INTERNAL_ALLOC_H
    1.33 +
    1.34 +# ifndef _STLP_CSTDDEF
    1.35 +#  include <cstddef>
    1.36 +# endif
    1.37 +
    1.38 +#if !defined (_STLP_DEBUG_H) && (defined  (_STLP_DEBUG) || defined (_STLP_ASSERTIONS))
    1.39 +# include <stl/debug/_debug.h>
    1.40 +#endif
    1.41 +
    1.42 +# ifndef _STLP_CSTDLIB
    1.43 +#  include <cstdlib>
    1.44 +# endif
    1.45 +# ifndef _STLP_CSTRING
    1.46 +#  include <cstring>
    1.47 +# endif
    1.48 +
    1.49 +# ifndef __THROW_BAD_ALLOC
    1.50 +#  if !defined(_STLP_USE_EXCEPTIONS)
    1.51 +#   if !defined (_STLP_CSTDIO)
    1.52 +#    include <cstdio>
    1.53 +#   endif
    1.54 +#   if !defined (_STLP_CSTDLIB)
    1.55 +#    include <cstdlib>
    1.56 +#   endif
    1.57 +#   define __THROW_BAD_ALLOC puts("out of memory\n"); exit(1)
    1.58 +#  else /* !defined(_STLP_USE_EXCEPTIONS) */
    1.59 +#   define __THROW_BAD_ALLOC throw _STLP_STD::bad_alloc()
    1.60 +#  endif /* !defined(_STLP_USE_EXCEPTIONS) */
    1.61 +# endif   /* __THROW_BAD_ALLOC */
    1.62 +
    1.63 +# ifndef _STLP_INTERNAL_NEW_HEADER
    1.64 +#  include <stl/_new.h>
    1.65 +# endif
    1.66 +
    1.67 +// #if ! defined (__SYMBIAN32__)
    1.68 +#if /* defined (_STLP_THREADS) && */ ! defined (_STLP_INTERNAL_THREADS_H)
    1.69 +# include <stl/_threads.h>
    1.70 +// #endif
    1.71 +#endif
    1.72 +
    1.73 +#ifndef _STLP_INTERNAL_CONSTRUCT_H
    1.74 +# include <stl/_construct.h>
    1.75 +#endif
    1.76 +
    1.77 +#ifndef __ALLOC
    1.78 +#   define __ALLOC __sgi_alloc
    1.79 +#endif
    1.80 +
    1.81 +# ifndef __RESTRICT
    1.82 +#  define __RESTRICT
    1.83 +# endif
    1.84 +
    1.85 +#if defined (_STLP_THREADS) || (defined(_STLP_OWN_IOSTREAMS) && ! defined (_STLP_NO_THREADS) && ! defined (_NOTHREADS) )
    1.86 +# define _STLP_NODE_ALLOCATOR_THREADS true
    1.87 +#else
    1.88 +# define _STLP_NODE_ALLOCATOR_THREADS false
    1.89 +#endif
    1.90 +
    1.91 +_STLP_BEGIN_NAMESPACE
    1.92 +
    1.93 +# if defined (_STLP_USE_RAW_SGI_ALLOCATORS)
    1.94 +template <class _Tp, class _Alloc> struct __allocator;
    1.95 +# endif
    1.96 +
    1.97 +#ifndef _STLP_NO_NODE_ALLOC
    1.98 +
    1.99 +// Malloc-based allocator.  Typically slower than default alloc below.
   1.100 +// Typically thread-safe and more storage efficient.
   1.101 +
   1.102 +typedef void (* __oom_handler_type)();
   1.103 +
   1.104 +template <int __inst>
   1.105 +class __malloc_alloc {
   1.106 +private:
   1.107 +  static void* _STLP_CALL _S_oom_malloc(size_t);
   1.108 +  static __oom_handler_type __oom_handler;
   1.109 +public:
   1.110 +  // this one is needed for proper simple_alloc wrapping
   1.111 +  typedef char value_type;
   1.112 +# if defined (_STLP_MEMBER_TEMPLATE_CLASSES) && defined (_STLP_USE_RAW_SGI_ALLOCATORS)
   1.113 +  template <class _Tp1> struct rebind {
   1.114 +    typedef __allocator<_Tp1, __malloc_alloc<__inst> > other;
   1.115 +  };
   1.116 +# endif
   1.117 +  static void* _STLP_CALL allocate(size_t __n)    {
   1.118 +    void* __result = malloc(__n);
   1.119 +    if (0 == __result) __result = _S_oom_malloc(__n);
   1.120 +    return __result;
   1.121 +  }
   1.122 +  static void _STLP_CALL deallocate(void* __p, size_t /* __n */) { free((char*)__p); }
   1.123 +  static __oom_handler_type _STLP_CALL set_malloc_handler(__oom_handler_type __f) {
   1.124 +    __oom_handler_type __old = __oom_handler;
   1.125 +    __oom_handler = __f;
   1.126 +    return(__old);
   1.127 +  }
   1.128 +};
   1.129 +
   1.130 +# endif
   1.131 +
   1.132 +// New-based allocator.  Typically slower than default alloc below.
   1.133 +// Typically thread-safe and more storage efficient.
   1.134 +class _STLP_CLASS_DECLSPEC __new_alloc {
   1.135 +public:
   1.136 +  // this one is needed for proper simple_alloc wrapping
   1.137 +  typedef char value_type;
   1.138 +# if defined (_STLP_MEMBER_TEMPLATE_CLASSES) &&  defined(_STLP_USE_RAW_SGI_ALLOCATORS)
   1.139 +  template <class _Tp1> struct rebind {
   1.140 +    typedef __allocator<_Tp1, __new_alloc > other;
   1.141 +  };
   1.142 +# endif
   1.143 +  static void* _STLP_CALL  allocate(size_t __n) {  
   1.144 +    return __stl_new(__n); 
   1.145 +  }
   1.146 +  static void _STLP_CALL deallocate(void* __p, size_t) { __stl_delete(__p); }
   1.147 +};
   1.148 +
   1.149 +
   1.150 +// Allocator adaptor to check size arguments for debugging.
   1.151 +// Reports errors using assert.  Checking can be disabled with
   1.152 +// NDEBUG, but it's far better to just use the underlying allocator
   1.153 +// instead when no checking is desired.
   1.154 +// There is some evidence that this can confuse Purify.
   1.155 +// This adaptor can only be applied to raw allocators
   1.156 +
   1.157 +template <class _Alloc>
   1.158 +class __debug_alloc : public _Alloc {
   1.159 +public:
   1.160 +  typedef _Alloc __allocator_type;
   1.161 +  typedef typename _Alloc::value_type value_type;
   1.162 +private:
   1.163 +  struct __alloc_header {
   1.164 +    size_t __magic: 16;
   1.165 +    size_t __type_size:16;
   1.166 +    _STLP_UINT32_T _M_size;
   1.167 +  }; // that is 8 bytes for sure
   1.168 +  // Sunpro CC has bug on enums, so extra_before/after set explicitly
   1.169 +  enum { __pad=8, __magic=0xdeba, __deleted_magic = 0xdebd,
   1.170 +	 __shred_byte= _STLP_SHRED_BYTE
   1.171 +  };
   1.172 +
   1.173 +  enum { __extra_before = 16, __extra_after = 8 };
   1.174 +  // Size of space used to store size.  Note
   1.175 +  // that this must be large enough to preserve
   1.176 +  // alignment.
   1.177 +  static size_t _STLP_CALL __extra_before_chunk() {
   1.178 +    return (long)__extra_before/sizeof(value_type)+
   1.179 +      (size_t)((long)__extra_before%sizeof(value_type)>0);
   1.180 +  }
   1.181 +  static size_t _STLP_CALL __extra_after_chunk() {
   1.182 +    return (long)__extra_after/sizeof(value_type)+
   1.183 +      (size_t)((long)__extra_after%sizeof(value_type)>0);
   1.184 +  }
   1.185 +public:
   1.186 +# if defined (_STLP_MEMBER_TEMPLATE_CLASSES) && defined (_STLP_USE_RAW_SGI_ALLOCATORS)
   1.187 +  template <class _Tp1> struct rebind {
   1.188 +    typedef __allocator< _Tp1, __debug_alloc<_Alloc> > other;
   1.189 +  };
   1.190 +# endif
   1.191 +  __debug_alloc() {}
   1.192 +  ~__debug_alloc() {}
   1.193 +  static void * _STLP_CALL allocate(size_t);
   1.194 +  static void _STLP_CALL deallocate(void *, size_t);
   1.195 +};
   1.196 +
   1.197 +# if defined(__OS400__)
   1.198 +enum {_ALIGN = 16, _ALIGN_SHIFT=4, _MAX_BYTES = 256};
   1.199 +#  define  _STLP_NFREELISTS 16
   1.200 +# else
   1.201 +enum {_ALIGN = 8, _ALIGN_SHIFT=3, _MAX_BYTES = 128};
   1.202 +#  define  _STLP_NFREELISTS 16
   1.203 +# endif /* __OS400__ */
   1.204 +
   1.205 +#ifndef _STLP_NO_NODE_ALLOC
   1.206 +
   1.207 +// Default node allocator.
   1.208 +// With a reasonable compiler, this should be roughly as fast as the
   1.209 +// original STL class-specific allocators, but with less fragmentation.
   1.210 +// Default_alloc_template parameters are experimental and MAY
   1.211 +// DISAPPEAR in the future.  Clients should just use alloc for now.
   1.212 +//
   1.213 +// Important implementation properties:
   1.214 +// 1. If the client request an object of size > _MAX_BYTES, the resulting
   1.215 +//    object will be obtained directly from malloc.
   1.216 +// 2. In all other cases, we allocate an object of size exactly
   1.217 +//    _S_round_up(requested_size).  Thus the client has enough size
   1.218 +//    information that we can return the object to the proper free list
   1.219 +//    without permanently losing part of the object.
   1.220 +//
   1.221 +
   1.222 +// The first template parameter specifies whether more than one thread
   1.223 +// may use this allocator.  It is safe to allocate an object from
   1.224 +// one instance of a default_alloc and deallocate it with another
   1.225 +// one.  This effectively transfers its ownership to the second one.
   1.226 +// This may have undesirable effects on reference locality.
   1.227 +// The second parameter is unreferenced and serves only to allow the
   1.228 +// creation of multiple default_alloc instances.
   1.229 +
   1.230 +class _STLP_CLASS_DECLSPEC _Node_alloc_obj {
   1.231 +public:
   1.232 +    _Node_alloc_obj * _M_free_list_link;
   1.233 +};
   1.234 +
   1.235 +template <bool __threads, int __inst>
   1.236 +class __node_alloc {
   1.237 +  _STLP_PRIVATE:
   1.238 +  static inline size_t _STLP_CALL _S_round_up(size_t __bytes) { return (((__bytes) + (size_t)_ALIGN-1) & ~((size_t)_ALIGN - 1)); }
   1.239 +  typedef _Node_alloc_obj _Obj;
   1.240 +private:
   1.241 +  // Returns an object of size __n, and optionally adds to size __n free list.
   1.242 +  static void*  _STLP_CALL _S_refill(size_t __n);
   1.243 +  // Allocates a chunk for nobjs of size size.  nobjs may be reduced
   1.244 +  // if it is inconvenient to allocate the requested number.
   1.245 +  static char*  _STLP_CALL _S_chunk_alloc(size_t __p_size, int& __nobjs);
   1.246 +  // Chunk allocation state.
   1.247 +  static _Node_alloc_obj * _STLP_VOLATILE _S_free_list[_STLP_NFREELISTS]; 
   1.248 +  static char* _S_start_free;
   1.249 +  static char* _S_end_free;
   1.250 +  static size_t _S_heap_size;
   1.251 +  static void * _STLP_CALL _M_allocate(size_t __n);
   1.252 +  /* __p may not be 0 */
   1.253 +  static void _STLP_CALL _M_deallocate(void *__p, size_t __n);
   1.254 +public:
   1.255 +  // this one is needed for proper simple_alloc wrapping
   1.256 +  typedef char value_type;
   1.257 +# if defined (_STLP_MEMBER_TEMPLATE_CLASSES) && defined (_STLP_USE_RAW_SGI_ALLOCATORS)
   1.258 +  template <class _Tp1> struct rebind {
   1.259 +    typedef __allocator<_Tp1, __node_alloc<__threads, __inst> > other;
   1.260 +  };
   1.261 +# endif
   1.262 +  /* __n must be > 0      */
   1.263 +  static void * _STLP_CALL allocate(size_t __n) { 
   1.264 +return (__n > (size_t)_MAX_BYTES) ?  __stl_new(__n) : _M_allocate(__n); }
   1.265 +  /* __p may not be 0 */
   1.266 +  static void _STLP_CALL deallocate(void *__p, size_t __n) { 
   1.267 +if (__n > (size_t)_MAX_BYTES) __stl_delete(__p); else _M_deallocate(__p, __n); }
   1.268 +};
   1.269 +
   1.270 +# if defined (_STLP_USE_TEMPLATE_EXPORT)
   1.271 +_STLP_EXPORT_TEMPLATE_CLASS __malloc_alloc<0>;
   1.272 +_STLP_EXPORT_TEMPLATE_CLASS __node_alloc<_STLP_NODE_ALLOCATOR_THREADS, 0>;
   1.273 +# endif /* _STLP_USE_TEMPLATE_EXPORT */
   1.274 +typedef __node_alloc<_STLP_NODE_ALLOCATOR_THREADS, 0> _Node_alloc;
   1.275 +# if defined (_STLP_USE_TEMPLATE_EXPORT)
   1.276 +_STLP_EXPORT_TEMPLATE_CLASS __debug_alloc<_Node_alloc>;
   1.277 +_STLP_EXPORT_TEMPLATE_CLASS __debug_alloc<__new_alloc>;
   1.278 +_STLP_EXPORT_TEMPLATE_CLASS __debug_alloc<__malloc_alloc<0> >;
   1.279 +# endif
   1.280 +
   1.281 +#endif
   1.282 +
   1.283 +# if defined (_STLP_USE_PERTHREAD_ALLOC)
   1.284 +
   1.285 +_STLP_END_NAMESPACE
   1.286 +// include additional header here
   1.287 +# include <stl/_pthread_alloc.h>
   1.288 +_STLP_BEGIN_NAMESPACE
   1.289 +
   1.290 +#  if defined ( _STLP_DEBUG_ALLOC )
   1.291 +typedef __debug_alloc<__pthread_alloc> __sgi_alloc;
   1.292 +#  else
   1.293 +typedef __pthread_alloc __sgi_alloc;
   1.294 +#  endif /* _STLP_DEBUG_ALLOC */
   1.295 +
   1.296 +typedef __pthread_alloc __single_client_alloc;
   1.297 +typedef __pthread_alloc __multithreaded_alloc;
   1.298 +
   1.299 +# else
   1.300 +
   1.301 +# if defined ( _STLP_USE_NEWALLOC )
   1.302 +
   1.303 +#  if defined ( _STLP_DEBUG_ALLOC )
   1.304 +typedef __debug_alloc<__new_alloc> __sgi_alloc;
   1.305 +#  else
   1.306 +typedef __new_alloc __sgi_alloc;
   1.307 +#  endif /* _STLP_DEBUG_ALLOC */
   1.308 +
   1.309 +typedef __new_alloc __single_client_alloc;
   1.310 +typedef __new_alloc __multithreaded_alloc;
   1.311 +
   1.312 +#  elif defined (_STLP_USE_MALLOC)
   1.313 +
   1.314 +#   if defined ( _STLP_DEBUG_ALLOC )
   1.315 +typedef __debug_alloc<__malloc_alloc<0> > __sgi_alloc;
   1.316 +#   else
   1.317 +typedef __malloc_alloc<0> __sgi_alloc;
   1.318 +#   endif /* _STLP_DEBUG_ALLOC */
   1.319 +
   1.320 +typedef __malloc_alloc<0> __single_client_alloc;
   1.321 +typedef __malloc_alloc<0> __multithreaded_alloc;
   1.322 +
   1.323 +# else
   1.324 +
   1.325 +#   if defined ( _STLP_DEBUG_ALLOC )
   1.326 +typedef __debug_alloc<_Node_alloc> __sgi_alloc;
   1.327 +#   else
   1.328 +typedef _Node_alloc __sgi_alloc;
   1.329 +#   endif
   1.330 +
   1.331 +typedef __node_alloc<false, 0> __single_client_alloc;
   1.332 +typedef __node_alloc<true, 0>  __multithreaded_alloc;
   1.333 +
   1.334 +#  endif /* _STLP_USE_NEWALLOC */
   1.335 +# endif /* PTHREAD_ALLOC */
   1.336 +
   1.337 +// This implements allocators as specified in the C++ standard.  
   1.338 +//
   1.339 +// Note that standard-conforming allocators use many language features
   1.340 +// that are not yet widely implemented.  In particular, they rely on
   1.341 +// member templates, partial specialization, partial ordering of function
   1.342 +// templates, the typename keyword, and the use of the template keyword
   1.343 +// to refer to a template member of a dependent type.
   1.344 +
   1.345 +template <class _Tp>
   1.346 +class allocator {
   1.347 +public:
   1.348 +
   1.349 +  typedef _Tp        value_type;
   1.350 +  typedef value_type *       pointer;
   1.351 +  typedef const _Tp* const_pointer;
   1.352 +  typedef _Tp&       reference;
   1.353 +  typedef const _Tp& const_reference;
   1.354 +  typedef size_t     size_type;
   1.355 +  typedef ptrdiff_t  difference_type;
   1.356 +# if defined (_STLP_MEMBER_TEMPLATE_CLASSES)
   1.357 +  template <class _Tp1> struct rebind {
   1.358 +    typedef allocator<_Tp1> other;
   1.359 +  };
   1.360 +# endif
   1.361 +  allocator() _STLP_NOTHROW {}
   1.362 + # if defined (_STLP_MEMBER_TEMPLATES)
   1.363 +  template <class _Tp1> allocator(const allocator<_Tp1>&) _STLP_NOTHROW {}
   1.364 + # endif    
   1.365 +  allocator(const allocator<_Tp>&) _STLP_NOTHROW {}
   1.366 +  ~allocator() _STLP_NOTHROW {}
   1.367 +  pointer address(reference __x) const { return &__x; }
   1.368 +  const_pointer address(const_reference __x) const { return &__x; }
   1.369 +  // __n is permitted to be 0.  The C++ standard says nothing about what the return value is when __n == 0.
   1.370 +  _Tp* allocate(size_type __n, const void* = 0) { 
   1.371 +    return __n != 0 ? __REINTERPRET_CAST(value_type*,__sgi_alloc::allocate(__n * sizeof(value_type))) : 0;
   1.372 +  }
   1.373 +  // __p is permitted to be a null pointer, only if n==0.
   1.374 +  void deallocate(pointer __p, size_type __n) {
   1.375 +    _STLP_ASSERT( (__p == 0) == (__n == 0) )
   1.376 +      if (__p != 0) __sgi_alloc::deallocate((void*)__p, __n * sizeof(value_type));
   1.377 +  }
   1.378 +  // backwards compatibility
   1.379 +  void deallocate(pointer __p) const {  if (__p != 0) __sgi_alloc::deallocate((void*)__p, sizeof(value_type)); }
   1.380 +  size_type max_size() const _STLP_NOTHROW  { return size_t(-1) / sizeof(value_type); }
   1.381 +  void construct(pointer __p, const _Tp& __val) { _STLP_STD::_Construct(__p, __val); }
   1.382 +  void destroy(pointer __p) { _STLP_STD::_Destroy(__p); }
   1.383 +# if defined(__MRC__)||(defined(__SC__) && !defined(__DMC__))
   1.384 +  template <class _T2> bool operator==(const allocator<_T2>&) const  _STLP_NOTHROW { return true; }
   1.385 +  template <class _T2> bool operator!=(const allocator<_T2>&) const _STLP_NOTHROW { return false; }
   1.386 +# endif
   1.387 +};
   1.388 +
   1.389 +_STLP_TEMPLATE_NULL
   1.390 +class _STLP_CLASS_DECLSPEC allocator<void> {
   1.391 +public:
   1.392 +  typedef size_t      size_type;
   1.393 +  typedef ptrdiff_t   difference_type;
   1.394 +  typedef void*       pointer;
   1.395 +  typedef const void* const_pointer;
   1.396 +# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
   1.397 +  typedef void        value_type;
   1.398 +# endif
   1.399 +# if defined (_STLP_MEMBER_TEMPLATE_CLASSES)
   1.400 +  template <class _Tp1> struct rebind {
   1.401 +    typedef allocator<_Tp1> other;
   1.402 +  };
   1.403 +# endif
   1.404 +# if defined(__MRC__)||(defined(__SC__)&&!defined(__DMC__))		//*ty 03/24/2001 - MPW compilers get confused on these operator definitions
   1.405 +  template <class _T2> bool operator==(const allocator<_T2>&) const _STLP_NOTHROW { return true; }
   1.406 +  template <class _T2> bool operator!=(const allocator<_T2>&) const _STLP_NOTHROW { return false; }
   1.407 +# endif
   1.408 +};
   1.409 +
   1.410 +#if !(defined(__MRC__)||(defined(__SC__)&&!defined(__DMC__)))		//*ty 03/24/2001 - MPW compilers get confused on these operator definitions
   1.411 +template <class _T1, class _T2> inline bool  _STLP_CALL operator==(const allocator<_T1>&, const allocator<_T2>&) _STLP_NOTHROW { return true; }
   1.412 +template <class _T1, class _T2> inline bool  _STLP_CALL operator!=(const allocator<_T1>&, const allocator<_T2>&) _STLP_NOTHROW { return false; }
   1.413 +#endif
   1.414 +
   1.415 +# if defined (_STLP_USE_TEMPLATE_EXPORT)
   1.416 +_STLP_EXPORT_TEMPLATE_CLASS allocator<char>;
   1.417 +#  if defined (_STLP_HAS_WCHAR_T)
   1.418 +_STLP_EXPORT_TEMPLATE_CLASS allocator<wchar_t>;
   1.419 +#  endif
   1.420 +# endif /* _STLP_USE_TEMPLATE_EXPORT */
   1.421 +
   1.422 +// Another allocator adaptor: _Alloc_traits.  This serves two
   1.423 +// purposes.  First, make it possible to write containers that can use
   1.424 +// either SGI-style allocators or standard-conforming allocator.
   1.425 +
   1.426 +// The fully general version.
   1.427 +template <class _Tp, class _Allocator>
   1.428 +struct _Alloc_traits
   1.429 +{
   1.430 +  typedef _Allocator _Orig;
   1.431 +# if defined (_STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM) 
   1.432 +  typedef typename _Allocator::_STLP_TEMPLATE rebind<_Tp> _Rebind_type;
   1.433 +  typedef typename _Rebind_type::other  allocator_type;
   1.434 +  static allocator_type create_allocator(const _Orig& __a) { return allocator_type(__a); }
   1.435 +# else
   1.436 +  // this is not actually true, used only to pass this type through
   1.437 +  // to dynamic overload selection in _STLP_alloc_proxy methods
   1.438 +  typedef _Allocator allocator_type;
   1.439 +# endif /* _STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM */
   1.440 +};
   1.441 +
   1.442 +#ifndef _STLP_FORCE_ALLOCATORS
   1.443 +#define _STLP_FORCE_ALLOCATORS(a,y) 
   1.444 +#endif
   1.445 +
   1.446 +#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && ! defined (_STLP_MEMBER_TEMPLATE_CLASSES)
   1.447 +// The version for the default allocator, for rare occasion when we have partial spec w/o member template classes
   1.448 +template <class _Tp, class _Tp1>
   1.449 +struct _Alloc_traits<_Tp, allocator<_Tp1> > {
   1.450 +  typedef allocator<_Tp1> _Orig;
   1.451 +  typedef allocator<_Tp> allocator_type;
   1.452 +  static allocator_type create_allocator(const allocator<_Tp1 >& __a) { return allocator_type(__a); }
   1.453 +};
   1.454 +#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
   1.455 +
   1.456 +/* macro to convert the allocator for initialization
   1.457 + * not using MEMBER_TEMPLATE_CLASSES as it should work given template constructor  */
   1.458 +#if defined (_STLP_MEMBER_TEMPLATES) || ! defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
   1.459 +/* if _STLP_NO_TEMPLATE_CONVERSIONS is set, the member template constructor is
   1.460 + * not used implicitly to convert allocator parameter, so let us do it explicitly */
   1.461 +# if defined (_STLP_MEMBER_TEMPLATE_CLASSES) && defined (_STLP_NO_TEMPLATE_CONVERSIONS)
   1.462 +#  define _STLP_CONVERT_ALLOCATOR(__a, _Tp) __stl_alloc_create(__a,(_Tp*)0)
   1.463 +# else
   1.464 +#  define _STLP_CONVERT_ALLOCATOR(__a, _Tp) __a
   1.465 +# endif
   1.466 +/* else convert, but only if partial specialization works, since else
   1.467 + * Container::allocator_type won't be different */
   1.468 +#else 
   1.469 +#  define _STLP_CONVERT_ALLOCATOR(__a, _Tp) __stl_alloc_create(__a,(_Tp*)0)
   1.470 +#endif
   1.471 +
   1.472 +# if defined (_STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM) 
   1.473 +template <class _Tp, class _Alloc>
   1.474 +inline _STLP_TYPENAME_ON_RETURN_TYPE _Alloc_traits<_Tp, _Alloc>::allocator_type  _STLP_CALL
   1.475 +__stl_alloc_create(const _Alloc& __a, const _Tp*) {
   1.476 +  typedef typename _Alloc::_STLP_TEMPLATE rebind<_Tp>::other _Rebound_type;
   1.477 +  return _Rebound_type(__a);
   1.478 +}
   1.479 +#else
   1.480 +// If custom allocators are being used without member template classes support :
   1.481 +// user (on purpose) is forced to define rebind/get operations !!!
   1.482 +template <class _Tp1, class _Tp2>
   1.483 +inline allocator<_Tp2>& _STLP_CALL
   1.484 +__stl_alloc_rebind(allocator<_Tp1>& __a, const _Tp2*) {  return (allocator<_Tp2>&)(__a); }
   1.485 +template <class _Tp1, class _Tp2>
   1.486 +inline allocator<_Tp2> _STLP_CALL
   1.487 +__stl_alloc_create(const allocator<_Tp1>&, const _Tp2*) { return allocator<_Tp2>(); }
   1.488 +#endif /* _STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM */
   1.489 +
   1.490 +# ifdef _STLP_USE_RAW_SGI_ALLOCATORS
   1.491 +// move obsolete stuff out of the way
   1.492 +# include <stl/_alloc_old.h>
   1.493 +# endif
   1.494 +
   1.495 +// inheritance is being used for EBO optimization
   1.496 +template <class _Value, class _Tp, class _MaybeReboundAlloc>
   1.497 +class _STLP_alloc_proxy : public _MaybeReboundAlloc {
   1.498 +private:
   1.499 +  typedef _MaybeReboundAlloc _Base;
   1.500 +  typedef _STLP_alloc_proxy<_Value, _Tp, _MaybeReboundAlloc> _Self;
   1.501 +public:
   1.502 +  _Value _M_data;
   1.503 +  inline _STLP_alloc_proxy(const _MaybeReboundAlloc& __a, _Value __p) : _MaybeReboundAlloc(__a), _M_data(__p) {}
   1.504 +
   1.505 +# if 0
   1.506 +  inline _STLP_alloc_proxy(const _Self& __x) : _MaybeReboundAlloc(__x), _M_data(__x._M_data) {} 
   1.507 +  // construction/destruction
   1.508 +  inline _Self& operator = (const _Self& __x) { 
   1.509 +    *(_MaybeReboundAlloc*)this = *(_MaybeReboundAlloc*)__x;
   1.510 +    _M_data = __x._M_data; return *this; 
   1.511 +  } 
   1.512 +  inline _Self& operator = (const _Base& __x) { ((_Base&)*this) = __x; return *this; } 
   1.513 +# endif
   1.514 +  // Unified interface to perform allocate()/deallocate() with limited
   1.515 +  // language support
   1.516 +#if ! defined (_STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM)
   1.517 +  // else it is rebound already, and allocate() member is accessible
   1.518 +  inline _Tp* allocate(size_t __n) { 
   1.519 +    return __stl_alloc_rebind(__STATIC_CAST(_Base&,*this),(_Tp*)0).allocate(__n,0); 
   1.520 +  }
   1.521 +  inline void deallocate(_Tp* __p, size_t __n) { 
   1.522 +    __stl_alloc_rebind(__STATIC_CAST(_Base&, *this),(_Tp*)0).deallocate(__p, __n); 
   1.523 +  }
   1.524 +#endif /* !_STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM */
   1.525 +};
   1.526 +
   1.527 +# if defined (_STLP_USE_TEMPLATE_EXPORT)
   1.528 +_STLP_EXPORT_TEMPLATE_CLASS _STLP_alloc_proxy<char *,char,allocator<char> >;
   1.529 +#  if defined (_STLP_HAS_WCHAR_T)
   1.530 +_STLP_EXPORT_TEMPLATE_CLASS _STLP_alloc_proxy<wchar_t *,wchar_t,allocator<wchar_t> >;
   1.531 +#  endif
   1.532 +# endif /* _STLP_USE_TEMPLATE_EXPORT */
   1.533 +
   1.534 +# undef _STLP_NODE_ALLOCATOR_THREADS
   1.535 +
   1.536 +_STLP_END_NAMESPACE
   1.537 +
   1.538 +# if defined (_STLP_EXPOSE_GLOBALS_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
   1.539 +#  include <stl/_alloc.c>
   1.540 +# endif
   1.541 +
   1.542 +#endif /* _STLP_INTERNAL_ALLOC_H */
   1.543 +
   1.544 +// Local Variables:
   1.545 +// mode:C++
   1.546 +// End:
   1.547 +