What is the best way (in C ++) to configure a container for double indexing? In particular, I have a list of objects, each of which is indexed by a key (possibly several keys). This implies a multimap. The problem with this, however, is that it means that perhaps worse than a linear search to find the location of an object. I would prefer to avoid duplicating data, so it would be bad for each object to maintain its own coordinate and have to move on the map (not to mention that moving your own object can indirectly call your destructor while in the function- member!). I would prefer some container that maintains an index with both a pointer to an object and a coordinate, and that the objects themselves guarantee stable links / pointers.Then each object can store an iterator in the index (including the coordinate), it is enough to abstract and know where it is. Boost.MultiIndex seems like a better idea, but it's very scary, and I don't want my actual objects to need const.
What would you recommend?
EDIT: Boost Bimap seems nice, but does it provide stable indexing? That is, if I change the coordinate, links to other elements must remain valid. The reason I want to use pointers for indexing is because the objects otherwise do not have an internal order, and the pointer can remain constant while the object changes (allowing it to be used in Boost MultiIndex, which, IIRC, provides stable indexing) .
source
share