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