Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost.MultiIndex. Using several keys together.
From: Jason Roehm (jasonr_at_[hidden])
Date: 2014-02-05 08:12:35


On 02/04/2014 04:35 PM, syvyi wrote:
> What if the composite key should be parameterized from a file?
>
> In the case of
> <raw>
> struct phonebook_entry
> {
> std::string family_name;
> std::string given_name;
> std::string phone_number;
>
> phonebook_entry(
> std::string family_name,
> std::string given_name,
> std::string phone_number):
> family_name(family_name),given_name(given_name),phone_number(phone_number)
> {}
> };
>
> // define a multi_index_container with a composite key on
> // (family_name,given_name)
> typedef multi_index_container<
> phonebook_entry,
> indexed_by<
> //non-unique as some subscribers might have more than one number
> ordered_non_unique<
> composite_key<
> phonebook_entry,
> member<phonebook_entry,std::string,&phonebook_entry::family_name>,
> member<phonebook_entry,std::string,&phonebook_entry::given_name>
> >
> >,
> ordered_unique< // unique as numbers belong to only one subscriber
> member<phonebook_entry,std::string,&phonebook_entry::phone_number>
> >
> >
> > phonebook;
> </raw>
>
> the lines
> member<phonebook_entry,std::string,&phonebook_entry::family_name>,
> member<phonebook_entry,std::string,&phonebook_entry::given_name>
> should be auto-generated by reading a composite key from a file.

That use case sounds incompatible with composite keys, which must be
defined at compile time. In that case, I would recommend creating
individual indices on the container for each field that you might want
to use at runtime, but you would lose the composite key functionality.

Jason


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net