Den 23-11-2017 kl. 00:31 skrev Phil Endecott via Boost:
There's another way of implementing this, though; rather than pointing to the object in the heap you can store it in-place by allocating enough space for the largest possible derived subclass:
[snip]
That's just a sketch; many details omitted! There are some obvious advantages and disadvantages of each approach and I'm definitely not saying this is better than the pointer-to-heap design.
That's going to use way too much space, make swap/move slow and possibly noexcept(false), give poor reference stability. For that case of not heap-allocating each object in isolation, boost::poly_collection seems much better. So I would stick to the allocate on the heap approach. kind regards -Thorsten