C++11: Factory allocators?

This forum is reserved for everything you want to talk about. It could be about programming, opinions, open source programs, development in general, or just cool stuff to share!
Post Reply
beneficii
Earned some good credits
Earned some good credits
Posts: 111
Joined: Fri Nov 27, 2009 2:49 am

C++11: Factory allocators?

Post by beneficii »

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.
Post Reply