Boost logo

Boost :

Subject: Re: [boost] [cpo-proposal] presentation of the idea
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2013-08-16 07:00:57

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.


> int main(int argc, char** argv)
> {
> classifier<base, std::allocator> collection;
> collection.insert( derived_A(21) );
> collection.insert( derived_B(40) );
> classifier<base, std::allocator>::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<derived_A>( 21 );

using variadic templates.

> - 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<T*> of the elements
(Thus, push_back should probably return a pointer to the constructed

All in all, I hope you will persue this idea. I certainly have many
use-cases for it in code where efficiency matters, and in code where
using Boost.Intrusive is just must more work.

kind regards


Boost list run by bdawes at, gregod at, cpdaniel at, john at