how to lisk unique keys in boost multi_index_container
hello,every one now i have a struct like this struct a { a(const std::string &m1_, const std::string &m2_, boost::int16_t m3_) : m1(m1_),m2(m2_), m3(m3_) {} std::string m1; std::string m2; boost::int16_t m3; }; typedef boost::multi_index::multi_index_container < a, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< BOOST_MULTI_INDEX_MEMBER(a, std::string, m1) >, boost::multi_index::ordered_non_unique< BOOST_MULTI_INDEX_MEMBER(a, std::string, m2) >, boost::multi_index::ordered_non_unique < BOOST_MULTI_INDEX_MEMBER(a, boost::uint16_t, m3) > >
my_data; i want to list all unique keys of m2 and m3 after the container has been filled with a lot of records, is there a example ?
my_data data; data.insert(a("a1","k1", 1)); data.insert(a("a2","k1", 2)); data.insert(a("a3","k2", 3)); ..... data.insert(a("a10000","k1", 1)); i want to get all data that m2 equal to "k1", when this data has been processed, get all data that m2 equal to "k2" ... but i do not how many unique keys in the container, am i need to store another set to store that when i fill the container? i need a function to get the keys like the SQL:"select distinct(m2) from data". thanks a lot! best regards. Bill
Bill Tian
hello,every one now i have a struct like this
struct a { a(const std::string &m1_, const std::string &m2_, boost::int16_t m3_) : m1(m1_),m2(m2_), m3(m3_) {} std::string m1; std::string m2;
boost::int16_t m3; };
[...]
i want to get all data that m2 equal to "k1", when this data has been processed, get all data that m2 equal to "k2" ... but i do not how many unique keys in the container, am i need to store another set to store that when i fill the container? i need a function to get the keys like the SQL:"select distinct(m2) from data".
Something like that will do? for(auto it=data.get<1>().begin(),it_end=data.get<1>().end(); it!=it_end; it=data.get<1>().upper_bound(it->m2)){ std::cout<<it->m2<<"\n"; // or whatever you need to do with the key } Hope this helps, Joaquín M López Muñoz Telefónica
participants (2)
-
Bill Tian
-
Joaquin M Lopez Munoz