问题描述
我有一个Boost多索引结构,该结构将boost :: shared_ptr保留到A类的实例.当我使用索引之一的查找"功能时,我得到一个迭代器"it",从中可以通过A* a = it->get();
返回实际指针.知道多索引结构的erase
函数需要一个迭代器,而不是指针或boost :: shared_ptr,我如何才能从多索引中删除a
呢?问题是在程序中要删除对象的地方,我不再有我的初始迭代器,只有实际的指针.
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.
谢谢
推荐答案
没有这样的东西多索引结构的erase
功能".请注意,erase
是 index 的成员函数,其签名可能会因索引类型而异.
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.
尤其是,有序索引和哈希索引具有在erase
的超载之后:
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);
即如果shared_ptr
是键,则可以将其传递给erase
函数.当然,您可以先调用find
,获取迭代器并将其传递给erase
.
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
.
这篇关于从Boost MultiIndex中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!