How to write a custom predicate for multi_index_containder with composite_key?
Posted
by Titan
on Stack Overflow
See other posts from Stack Overflow
or by Titan
Published on 2010-06-10T11:28:37Z
Indexed on
2010/06/10
11:33 UTC
Read the original article
Hit count: 219
I googled and searched in the boost's man, but didn't find any examples. May be it's a stupid question...anyway.
So we have the famous phonebook from the man:
typedef multi_index_container<
phonebook_entry,
indexed_by<
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>
>,
composite_key_compare<
std::less<std::string>, // family names sorted as by default
std::greater<std::string> // given names reversed
>
>,
ordered_unique<
member<phonebook_entry,std::string,&phonebook_entry::phone_number>
>
>
> phonebook;
phonebook pb;
...
// look for all Whites
std::pair<phonebook::iterator,phonebook::iterator> p=
pb.equal_range(boost::make_tuple("White"), my_custom_comp());
How should my_custom_comp() look like? I mean it's clear for me then it takes boost::multi_index::composite_key_result<CompositeKey>
as an argumen (due to compilation errors :) ), but what is CompositeKey in that particular case?
struct my_custom_comp
{
bool operator()( ?? boost::multi_index::composite_key_result<CompositeKey> ?? ) const
{
return blah_blah_blah;
}
};
Thanks in advance.
© Stack Overflow or respective owner