Boost logo

Boost :

From: Bruno Martínez (br1_at_[hidden])
Date: 2006-01-19 09:03:39


On Thu, 19 Jan 2006 06:17:02 -0200, Joaquín Mª López Muñoz
<joaquin_at_[hidden]> wrote:

> Bruno Martínez ha escrito:
>
>> On Sat, 31 Dec 2005 18:01:00 -0200, Maxim Yegorushkin
>> <maxim.yegorushkin_at_[hidden]> wrote:
>>
>> > The most common use cases for intrusive containers are:
>> >
>> > * when one would like to store non-copyable elements in a container
>> > * when it's beneficial to avoid needless data copy in performance
>> > critical
>> > applications
>>
>> For me, it's the ability to get an iterator from a pointer.
>
> Leaving aside the extra benefits intrusive containers can bring in,
> the ability of getting an iterator from a pointer to the element is
> implementable for regular multi_index_containers --matter of fact,
> this feature is internally used in the preview 1.34 version of
> Boost.MultiIndex I announced yesterday.

Really? Great!

> * What is the envisioned application scenario for this feature?

I frequently do something like this:

#include <list>

struct part;

struct whole {
        std::list<part*> parts;
};

struct part {
        part(whole& w) : my_whole(&w) {
                        me = my_whole->parts.insert(my_whole->parts.end(), this);
        }
        ~part() {
                my_whole->parts.erase(me);
        }
        whole* my_whole;
        std::list<part*>::iterator me;
};

> * Would you advocate having it in Boost.MultiIndex?

Yes. I would like multi_index to evolve into a solution to representing
UML class diagrams in C++, the same way the StateCharts lib does for State
Charts. In that case all classes know in which collections they are, so
intrusion is natural. I find more natural to just declare in which
collections a class is.

Bruno


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