#ifndef INCLUDED_NEWALLOC_H_ #define INCLUDED_NEWALLOC_H_ #include template class NewAlloc: public std::allocator { template friend std::ostream &operator<<(std::ostream &out, NewAlloc const &alloc); Data *d_data; public: NewAlloc(); NewAlloc(Data const &data); NewAlloc(NewAlloc const &other); ~NewAlloc(); operator Data &(); NewAlloc &operator=(Data const &data); }; template NewAlloc::NewAlloc() : d_data(0) {} template NewAlloc::NewAlloc(Data const &data) : d_data(new Data(data)) {} template NewAlloc::NewAlloc(NewAlloc const &other) : d_data(new Data(*other.d_data)) {} template NewAlloc::~NewAlloc() { delete d_data; } template NewAlloc::operator Data &() { return *d_data; } template NewAlloc &NewAlloc::operator=(Data const &data) { *d_data = data; } template inline std::ostream &operator<<(std::ostream &out, NewAlloc const &alloc) { return out << *alloc.d_data; } #endif