I don't quite understand how it is possible that the same elements can appear in different intrusive containers while preserving the performance and memory usage guarantees that the boost::intrusive
documentation states.
The documentation says that:
an intrusive container does not store copies of passed objects, but it stores the objects themselves. The additional data needed to insert the object in the container must be provided by the object itself. For example, to insert
MyClass
in an intrusive container that implements a linked list,MyClass
must contain the needed next and previous pointers:
class MyClass
{
MyClass *next;
MyClass *previous;
// ...
};
When underlining the differences between STL and boost::intrusive containers, the documentation also says:
A non-intrusive container has some limitations:
An object can only belong to one container: If you want to share an object between two containers, you either have to store multiple copies of those objects or you need to use containers of pointers:
std::list<Object*>
.
Makes sense, an element can't be in two std::list
s. Okay. But how can one instance of type MyClass
be inserted in two different boost::intrusive::list
's, for example, considering that such an element can only have one pointer to the next element and one to the previous element. If I am not wrong, this only works if you assume that modifying one container might also modify the other one and vice-versa.
std::list.splice
deprecates intrusive lists – David