
On Thu, 19 Jan 2006 15:39:10 -0200, Joaquín Mª López Muñoz <joaquin@tid.es> wrote:
Bruno Martínez ha escrito:
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; };
OK, but seems to me the kind of idioms you propose are best served by an intrusive version of multi_index_container. The "pointer to iterator" feature does not help in isolation, if I'm understanding you right.
If I can get an iterator from a pointer, I don't have to store the iterator. I just get an iterator from this. Of course, it's more clear using intrusive containers. Multi_index allows to work with std::set-like containers more easily. For example, you can search for the key, not the whole element. This is sort of intrusive already, and I don't see anything bad in it. Whenever the element knows it's contained, intrusive is clearer. Bruno