我有一个用于MRU的bmi multi_index_container,定义如下
bmi::multi_index_container<Item, bmi::indexed_by<bmi::sequenced<>, bmi::hashed_unique<bmi::tag<hashed>, KeyExtractor>>>它实际上是基于体重指数示例。一旦插入和重新定位项目的头,一切都是好的。当我按键查找并检索它时,问题就开始了,如下所示。
item_type & get(const key_type & key) const
{
auto item = items.template get<hashed>().find(key);
if (item == items.template get<hashed>().end())
throw std::logic_error("Item not found");
//relocate the item to the head
return const_cast<item_type &>(*item);
}因为我是按键查看的,所以我使用了散列索引。然后,我必须在relocate上调用sequenced,但是来自另一个索引的迭代器当然不能工作。当然,迭代sequenced并找到相同的项是一个选项,但非常丑陋,效率也很低。还有别的办法吗?
发布于 2020-05-14 11:49:36
若要在不同索引的迭代器之间进行转换,请使用投影。
https://stackoverflow.com/questions/61795550
复制相似问题