|
Boost Users : |
Subject: [Boost-users] [multi_index] Introducing C++17 terse key specification syntax
From: Joaquin M López Muñoz (joaquinlopezmunoz_at_[hidden])
Date: 2018-08-22 10:57:29
Following some ideas discussed about a year ago, I've added a new
boost::multi_index::key construct allowing for a very terse
specification of predefined
key extractors in C++17 compliant environments. For instance, given
   struct phonebook_entry
   {
     std::string family_name;
     std::string given_name;
     std::string phone_number()const;
   };
   int num_calls(const phonebook_entry&);
a classical definition like
   typedef multi_index_container<
     phonebook_entry,
     indexed_by<
       ordered_unique<
const_mem_fun<phonebook_entry,std::string,&phonebook_entry::phone_number>
       >,
       ordered_unique<
         global_fun<const phonebook_entry&,int,num_calls>
       >,
       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>
         >
       >
     >
   > phonebook;
can now be written as
   typedef multi_index_container<
     phonebook_entry,
     indexed_by<
       ordered_unique<
         key<&phonebook_entry::phone_number>
       >,
       ordered_unique<
         key<num_calls>
       >,
       ordered_non_unique<
key<&phonebook_entry::family_name,&phonebook_entry::given_name>
       >
     >
   > phonebook;
If you have a C++17 compiler, you can play with this new feature by
simply copying
https://github.com/boostorg/multi_index/blob/develop/include/boost/multi_index/key.hpp
into your local Boost installation. More info at
https://www.boost.org/doc/libs/develop/libs/multi_index/doc/tutorial/key_extraction.html#key
https://www.boost.org/doc/libs/develop/libs/multi_index/doc/reference/key_extraction.html#key_synopsis
Comments and suggestions, specially before Boost 1.69 ships and this becomes
more or less frozen, are most welcome.
Best regards,
JoaquÃn M López Muñoz
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