Boost 다중 인덱스 반복기에서 숫자 인덱스 가져 오기
로 정의 된 Boost.MultiIndex 컨테이너에 다음struct Article {
std::string title;
unsigned db_id; // id field in MediaWiki database dump
};
struct Article {
std::string title;
unsigned db_id; // id field in MediaWiki database dump
};
을 저장하고 있습니다.
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;
이제 두 개의 반복기가 있습니다. 하나는 index<by_title>
에서 하나는 index<by_id>
에서입니다. struct Article
에 데이터 멤버를 추가하지 않고 이들을 컨테이너의 임의 액세스 부분으로 인덱스로 변환하는 가장 쉬운 방법은 무엇입니까?
그래서 iterator_to (* it)는 임의 액세스 반복자를 제공합니까? 그리고 그것을 숫자 인덱스로 변환하려면 어떻게해야합니까? 매트릭스에 인덱스하기 위해 꼭 필요하기 때문입니다. –
@larsman - random_indexed 코드의 내부에서 판단 할 때, 그러한 인덱스에 대한 반복자는 차이가 있습니다. 'iter - index.begin()'이 작동해야합니다. 편집을 참조하십시오. –