Question

I have a boost multi-index structure that keeps boost::shared_ptr to instances of a class A. When I use the "find" function of one of the index, I get an iterator "it" from which I can get back the actual pointer through A* a = it->get();. How can I delete a from the multi-index knowing that the erase function of the multi-index structure takes an iterator, not a pointer nor a boost::shared_ptr? The thing is at the point of the program where I want to erase the object, I don't have anymore my initial iterator, only the actual pointer.

Thanks

Was it helpful?

Solution

There is no such thing "erase function of the multi-index structure". Note that erase is a member-function of an index, and its signature may vary depending on the index type.

In particular, ordered and hashed indices have the following overloads of erase:

iterator  erase(iterator position);
size_type erase(const key_type& x);
iterator  erase(iterator first,iterator last);

I.e. if shared_ptr is a key, you definitely can pass it to erase function. Of course, you can call find first, get the iterator and pass it to erase.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top