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 #ifndef _NEW_ALLOCATOR_H
00035 #define _NEW_ALLOCATOR_H 1
00036
00037 #include <new>
00038 #include <bits/functexcept.h>
00039
00040 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
00041
00042 using std::size_t;
00043 using std::ptrdiff_t;
00044
00045
00046
00047
00048
00049
00050
00051
00052 template<typename _Tp>
00053 class new_allocator
00054 {
00055 public:
00056 typedef size_t size_type;
00057 typedef ptrdiff_t difference_type;
00058 typedef _Tp* pointer;
00059 typedef const _Tp* const_pointer;
00060 typedef _Tp& reference;
00061 typedef const _Tp& const_reference;
00062 typedef _Tp value_type;
00063
00064 template<typename _Tp1>
00065 struct rebind
00066 { typedef new_allocator<_Tp1> other; };
00067
00068 new_allocator() throw() { }
00069
00070 new_allocator(const new_allocator&) throw() { }
00071
00072 template<typename _Tp1>
00073 new_allocator(const new_allocator<_Tp1>&) throw() { }
00074
00075 ~new_allocator() throw() { }
00076
00077 pointer
00078 address(reference __x) const { return &__x; }
00079
00080 const_pointer
00081 address(const_reference __x) const { return &__x; }
00082
00083
00084
00085 pointer
00086 allocate(size_type __n, const void* = 0)
00087 {
00088 if (__builtin_expect(__n > this->max_size(), false))
00089 std::__throw_bad_alloc();
00090
00091 return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)));
00092 }
00093
00094
00095 void
00096 deallocate(pointer __p, size_type)
00097 { ::operator delete(__p); }
00098
00099 size_type
00100 max_size() const throw()
00101 { return size_t(-1) / sizeof(_Tp); }
00102
00103
00104
00105 void
00106 construct(pointer __p, const _Tp& __val)
00107 { ::new(__p) _Tp(__val); }
00108
00109 void
00110 destroy(pointer __p) { __p->~_Tp(); }
00111 };
00112
00113 template<typename _Tp>
00114 inline bool
00115 operator==(const new_allocator<_Tp>&, const new_allocator<_Tp>&)
00116 { return true; }
00117
00118 template<typename _Tp>
00119 inline bool
00120 operator!=(const new_allocator<_Tp>&, const new_allocator<_Tp>&)
00121 { return false; }
00122
00123 _GLIBCXX_END_NAMESPACE
00124
00125 #endif