Boost logo

Boost :

Subject: Re: [boost] [cpo-proposal] presentation of the idea
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2013-08-28 03:18:03


On Fri, Aug 16, 2013 at 5:21 PM, Santiago Tapia <santiago.tapia_at_[hidden]>wrote:

> > Date: Tue, 13 Aug 2013 23:33:25 +0400
> > From: Andrey Semashev <andrey.semashev_at_[hidden]>
> >>
> >> - The container classifier is _not_ a sequence.
> >
> > Why? Is this intentional?
>
> Both intentional and accidental, because I want to allocate objects
> contiguously in memory I have to store them in a collection of
> vectors, the container is not a sequence but a collection of sequences,
> one sequence for every class in the classifier.
> I will implement a sequence, but later.
>

The storage strategy does not mandate the interface of the container.
unordered_set/map are implemented as a number of buckets (i.e.
single-linked lists), yet they provide sequence interface with an
additional ability to iterate within a single bucket. I don't see why a
similar approach couldn't be taken in your container.

> > All in all the basic idea looks interesting, although I'm not sure about
> the
> > particular classifier container. It looks very specific to me, the same
> > functionality could be achieved with a multimap or unordered_multimap of
> > polymorphic elements.
> >
> > ...or I should have said "multiset or unordered_multiset".
>
> As far as I know it is not possible to get a multimap of a pure abstract
> class,
> therefore, for example, you can not use a multimap<string, shape> or
> multiset<shape> but you can use a classifier<shape> to store triangles,
> squares, or any derived class. I plan to implement an associate container
> later, thus you could have classifier<string, shape> and you could look for
> an object in the classifier using a key.
>

You can't create std::multiset<shape> but you can create
boost::intrusive::multiset<shape>. The reason for that is that
std::multiset attempts to allocate storage for shape, while
boost::intrusive::multiset doesn't, leaving this to the user. This allows
you to insert any objects derived from shape to the single
boost::intrusive::multiset and work with this container pretty much the
same way you would with std::multiset. You can even insert the very same
object in multiple containers if you need to. I recommend you to have a
look at Boost.Intrusive, it is a truly amazing library.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk