得到升压多指标的迭代数字索引 [英] Get numeric index from Boost multi-index iterator
问题描述
我存储了一堆以下
struct Article {
std::string title;
unsigned db_id; // id field in MediaWiki database dump
};
在Boost.MultiIndex的容器,定义为
in a Boost.MultiIndex container, defined as
typedef boost::multi_index_container<
Article,
indexed_by<
random_access<>,
hashed_unique<tag<by_db_id>,
member<Article, unsigned, &Article::db_id> >,
hashed_unique<tag<by_title>,
member<Article, std::string, &Article::title> >
>
> ArticleSet;
现在我有两个迭代器,一个来自指数&LT; by_title&GT;
和一个从指数&LT; by_id&GT;
。这是对这些变换索引到容器的随机接入部分的最简单的方法,而无需增加数据成员结构条
Now I've got two iterators, one from index<by_title>
and one from index<by_id>
. What is the easiest way to transform these to indexes into the random access part of the container, without adding a data member to struct Article
?
推荐答案
各项指标利用价值支持新一代的迭代器的<一个href=\"http://www.boost.org/doc/libs/1_44_0/libs/multi_index/doc/reference/ord_indices.html#synopsis\">iterator_to.如果你已经有一个迭代的目标值在一个索引中,你可以使用它来转换为迭代器在另一个索引。
Every index supports generation of an iterator by value using iterator_to. If you already have an iterator to the target value in one index, you could use this to convert to an iterator in another index.
iterator iterator_to(const value_type& x);
const_iterator iterator_to(const value_type& x)const;
有关转换为指数则可能可以遵循模型 random_access_index.hpp
:
For conversion to index you can likely follow the model in random_access_index.hpp
:
iterator erase(iterator first,iterator last)
{
BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(first);
BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(last);
BOOST_MULTI_INDEX_CHECK_IS_OWNER(first,*this);
BOOST_MULTI_INDEX_CHECK_IS_OWNER(last,*this);
BOOST_MULTI_INDEX_CHECK_VALID_RANGE(first,last);
BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT;
difference_type n=last-first;
relocate(end(),first,last);
while(n--)pop_back();
return last;
}
这篇关于得到升压多指标的迭代数字索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!