Re: A deque containing different types of objects (with a common
base class)
Kai-Uwe Bux wrote:
typedef void ( *destr_fct ) ( AllignedPod & );
destr_fct the_destr_fct;
~polymorphic_var ( void ) {
the_destr_fct( the_data );
}
Why? Ever heard of virtual destructors? They are needed for vectors
containing (smart) pointers to allocated objects too. Why would you want
to store a function pointer to a destructor function separately?
As for the copying function, I said in my original post that functions
requiring copying or assignment (such as erase()) could simply not be
implemented. I think the container would still be useful.
The only memory required for this is size()*sizeof(LargestObject) +
some minor ancillary data required for a deque-type container.
As for "you are using premature optimization", if my concern was not
memory usage then I would use some std::vector<SmartPointer<Base> > and
not worry about the memory usage. However, sometimes memory-efficient
data containers are useful. It's not "premature optimization" to use
one, given that it's easy to use, abstract, and has been thoroughly tested.