2010/2/22 Andrew Kokkalis <andrewkokkalis@gmail.com>:
Declaration of my container is below: struct counterpart { string word; int id; float tf_idf;
counterpart(string word_, int id_) {
Prefer an initializer list: counterpart(string word, int id) : word(word), id(id), tf_idf(0.0) {}
};
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;
Each index of word_index acts/behaves like the corresponding STL container, and word_index "derives" from its first index so also behaves like it. So to search by word (first index), simply do a word_set.find() with a string. To search by any index, first get a *reference* to that index, e.g. word_set.get<word_id>(), and then again use it according to its API. Set operations on ordered indexes are documented here: http://www.boost.org/doc/libs/1_41_0/libs/multi_index/doc/reference/ord_indi... Modifying elements is a little different, to allow the multi-index container to check them against all its indexes and possibly veto them, with optional commit/rollback semantic. I suggest you go thru the tutorial where all this is described. --DD