Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.0 KiB

  1. template< class T>
  2. class allocator;
  3. template<>
  4. class allocator< void>
  5. {
  6. public: // Types
  7. typedef void* pointer;
  8. typedef const void* const_pointer;
  9. typedef void value_type;
  10. template< class U>
  11. struct rebind
  12. {
  13. typedef allocator< U> other;
  14. };
  15. };
  16. template< class T>
  17. class allocator
  18. {
  19. public: // Types
  20. typedef T value_type;
  21. typedef size_t size_type;
  22. typedef ptrdiff_t difference_type;
  23. typedef T* pointer;
  24. typedef T const * const_pointer;
  25. typedef T& reference;
  26. typedef T const & const_reference;
  27. template< class U>
  28. struct rebind
  29. {
  30. typedef allocator< U> other;
  31. };
  32. public: // Functions
  33. pointer address( reference r) const
  34. { return &r; }
  35. const_pointer address( const_reference r) const
  36. { return &r; }
  37. allocator() throw()
  38. { }
  39. template< class U>
  40. allocator( const allocator< U>& Other) throw()
  41. { }
  42. ~allocator() throw()
  43. { }
  44. template< class U>
  45. bool operator==( const allocator< U>& Other) throw()
  46. { return true; }
  47. template< class U>
  48. bool operator!=( const allocator< U>& Other) throw()
  49. { return false; }
  50. pointer allocate( size_type n, allocator<void>::const_pointer hint= 0)
  51. throw( bad_alloc)
  52. {
  53. void* pRet= NULL;
  54. try {
  55. if( n<= max_size())
  56. pRet= operator new ( n* sizeof(value_type));
  57. } catch( ... ) {
  58. }
  59. if( NULL== pRet)
  60. throw bad_alloc();
  61. return reinterpret_cast< pointer>( pRet);
  62. }
  63. void deallocate( pointer p, size_type n)
  64. { operator delete (static_cast<void*>(p)); }
  65. void construct( pointer p, const T& val)
  66. { new (p) T( val); }
  67. void destroy( pointer p)
  68. { p->~T(); }
  69. size_type max_size() const throw()
  70. {
  71. numeric_limits< size_type> Dummy;
  72. const size_type uiRet( Dummy.max()- 1); // -1 for realistic safety.
  73. return (0== sizeof( T)? uiRet: uiRet/ sizeof( T));
  74. }
  75. };