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!
beneficii
Experienced Solver
Experienced Solver
Posts: 93
Joined: Fri Nov 27, 2009 2:49 am

C++11: Factory allocators?

Postby beneficii » Thu Jun 19, 2014 8:35 am

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.

Return to “Open Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest