Boost logo

Boost Users :

Subject: Re: [Boost-users] how to lisk unique keys in boost multi_index_container
From: Joaquin M Lopez Munoz (joaquin_at_[hidden])
Date: 2014-12-02 12:43:16

Bill Tian <billtian945 <at>> writes:

> 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();
     std::cout<<it->m2<<"\n"; // or whatever you need to do with the key

Hope this helps,

Joaquín M López Muñoz

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at