Listing 1: A simple arena class
#include <vector> class arena { private: struct holder { virtual ~holder() { } }; template <class T> struct obj_holder : public holder { T obj; template <class Arg1> obj_holder(Arg1 arg1) : obj(arg1) { } }; std::vector<holder*> owned; private: arena(const arena&); void operator=(const arena&); public: arena() { } ~arena() { destroy_all(); } template <class T, class Arg1> T* create(Arg1 arg1) { obj_holder<T>* p = new obj_holder<T>(arg1); owned.push_back(p); return &p->obj; } void destroy_all() { std::vector<holder*>::size_type i = 0; while (i < owned.size()) { delete owned[i]; ++i; } owned.clear(); } };