boost::ptr_set is a container for storing pointers that behaves a std::set. boost::ptr_set will delete all stored pointers when it goes out of scope.
#include <boost/ptr_container/ptr_set.hpp> struct MyClass { MyClass(const int x = 0) : mX(x) {} const int mX; }; bool operator<(const MyClass lhs, const MyClass rhs) { return lhs.mX < rhs.mX; } int main() { boost::ptr_set<MyClass> s; s.insert(new MyClass); }