deleting from a Boost MultiIndex

瘦欲@ 提交于 2019-12-10 16:02:20

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/11558399/deleting-from-a-boost-multiindex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!