C++11: Factory allocators?
C++11: Factory allocators?
Let's say that I have a base class, with many classes derived through inheritance, and I want to store all instances of the base/derived classes in a container storing, say, smart pointers of the type std::unique_ptr<base>, which stores a pointer to the base class. It seems that with the addition of the emplace() methods to the STL, it would be feasible, perhaps even more efficient than otherwise, to write a custom allocator whose construct() method acts as a factory for producing a pointer of the correct base/derived class and then setting the std::unique_ptr<base> smart pointer that is being constructed inside the container to point to the base/derived class.