On 28-08-2013 06:51, Gottlob Frege wrote:
<snip> big thread about polymorphic container ... </snip>
I hope I didn't miss anything in the thread. If I'm repeating something, sorry.
I don't think we want or need to limit what we put into the container. Neither by forcing certain virtual functions onto the base class, nor by limiting what the contained types can and can't do (like have pointers to themselves and do funky things in their copy/move constructors).
When push_back<Triangle> is called, we create an instance of an ItemHandler<Triangle> class, that derives from BaseItemHandler, and implements copy/move virtually. ie type-erasure. ItemHandler<Triangle> knows how to move/copy Triangles. It is not Triangle's job!
We put the ItemHandler<Triangle> in a map
.
[Thorsten:] This is a bad idea IMO. The point of such a container is to provide as little fragmentation of the heap as possible, to get better locality of data (when the data consists of polymorphic objetcs). With std::vector<int> we get great locality. We don't yet have such an alternative for polymorphic objects. kind regards -Thorsten