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.



2014-02-04 Jason [via Boost] <[hidden email]>:

On 02/04/2014 03:36 PM, syvyi wrote:

> Hello,
>
> there's a structure
> struct person
> {
> std::string name;
> std::string surname;
> int birth_year;
> std::string craft;
> };
>
> How to create such a multiindex container that dumping could performed using
> an index as name, surname and year triple alltogether?
Sounds like you might be interested in MultiIndex's composite key feature:

http://www.boost.org/doc/libs/1_55_0/libs/multi_index/doc/tutorial/key_extraction.html#composite_keys

Jason
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users



If you reply to this email, your message will be added to the discussion below:
http://boost.2283326.n4.nabble.com/Boost-MultiIndex-Using-several-keys-together-tp4658953p4658955.html
To unsubscribe from Boost.MultiIndex. Using several keys together., click here.
NAML



View this message in context: Re: Boost.MultiIndex. Using several keys together.
Sent from the Boost - Users mailing list archive at Nabble.com.