First of all, i'm a programmer with no much experience using Boost Libraries.
I'm using Boost for academic purposes and here's my problem.
I simply want to access an element of a multi_index_container, by using the iterator_to iterator.
the container has entries that are <word(string), word_id(int), tf_idf(float)>
and is indexed by unique order for the first two values :word and word_id.
Declaration of my container is below:
struct counterpart {
string word;
int id;
float tf_idf;
counterpart(string word_, int id_) {
word = word_;
id = id_;
tf_idf = 0.0;
}
};
struct word_name{}; //or word char
struct word_id{};
struct word_tf_idf{};
typedef multi_index_container<
counterpart,
indexed_by<
ordered_unique<
tag<word_name>, BOOST_MULTI_INDEX_MEMBER(counterpart, string, word)>,
ordered_unique<
tag<word_id>, BOOST_MULTI_INDEX_MEMBER(counterpart, int, id)>,
ordered_non_unique<
tag<word_tf_idf>, BOOST_MULTI_INDEX_MEMBER(counterpart, float, tf_idf)> >
> word_index;
word_index word_set;
int word_count_id = 1;
From main, I insert some "entries" like below.
This a test main
int main(void){
//insert to word_set
pair<word_index::iterator, bool> word_pair;
if((word_pair = word_set.insert(counterpart("apple", word_count_id))).second) //word does not exist
word_count_id++;
}
I want to access the entry inserted, as i could do with a map. ex map["apple"]
The reason i do this, is because i want to get the value of a unique word_id, by accessing the name of the word
and a unique word name by accessing a word_id.
This of course is not possible, so i have to use iterator_to.
But i cannot think how to do this.
Should i prepeare a pair as donne when inserting?
Also how a value or an entire entry is returned? In which form?
Thank you all and I hope you can help me!
Andrew Kokkalis
undergraduate student of
Informatics and Telecomunications University of Athens, Greece