#include <iostream>
template<typename T>
inline T* _allocate(unsigned int size,T*){//size
T *temp=static_cast<T*>(operator new((size_t)size * sizeof(T)));
if(temp==NULL){
std::cout<<"out of memory"<<endl;
exit(1);
}
return temp;
}
template<typename T>
inline void _deallocate(T* buffer){
operator delete(buffer);
}
template<typename T1,typename T2>
inline void _construct(T1 *p,const T2& value){//p指向的分配的内存 value为构造的值
new(p) T1(value);//在p指向的内存空间创建一个类型为T1的对象 调用T的构造函数接受const T2&类型的value
}
template<typename T>
inline void _destroy(T* ptr){
ptr->~T();
}
template<typename T>
class myallocator{
puclic:
typedef T value_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef T& reference;
typedef const T& const_reference;
typedef unsigned int size_type;
template <class U>
struct rebind{
typedef allocator<U> other;
};
pointer allocate(size_type n,const void* hint=0){
return _allocate(difference_type(n),(pointer)0);
}
void deallocate(pointer buffer){
_deallocate(buffer);
}
void construct(pointer p,const T& value){
_construct(p,value);
}
void destroy(pointer p){
_destroy(p);
}
};