Hi Santiago,
Hi everyone,
I would like to make a proposal for a new library. I only have a draft without documentation but I would like to know people’s opinion about the idea before making a formal proposal.
The library will be named CPO (containers for polymorphic objects) and it will provide containers to store dynamic allocated objects from a class hierarchy. I have drafted one container and I have two more in process.
[snip]
int main(int argc, char** argv) { classifier
collection; collection.insert( derived_A(21) ); collection.insert( derived_B(40) );
classifier
::iterator i, e = collection.end(); for ( i = collection.begin(); i != e; ++i ) { const base& x = *i; std::cout << x.do_something(6) << std::endl; }
return 0; }
I would like to see the use of forwrding in-place construction:
collection.push_back
- The container's name is classifier because it classifies objects internally using the RTTI.
I had similar ideas that I wanted to implement. I didn't expect to use RTTI. Basically I wanted the class hierarchy's base class to derive from a class with pure virtual functions that allowed the container to perform the inplace-contruction, copying and alignment stuff.
- The container classifier is _not_ a sequence.
I would expect the container to allow forward iteration. I assume you mean that erase/insert into the middle is prohibited? I imagined that only push_back/pop_back was supported.
- The classifier uses continuous storage in memory for objects of the same type, therefore it is expected to improve cache efficiency with respect to solutions that use pointers (and new to allocate objects), especially if the client code uses some cache-aware allocator.
I wanted to call my class template polymorphic_vector, taking base class
and allocator template arguments. I imagined that the storage
would be completely contigious, even when many different types of
objects where stored into the container. This would give maximum cache
efficiency. Then if the user wanted to sort or otherwise manipulate the
sequence, he could just create an std::vector