所以我们有一个着名的电话簿:
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());
my_custom_comp()应该如何?我的意思是对我来说很明显然后它需要boost::multi_index::composite_key_result<CompositeKey>
作为论证(由于编译错误:)),但在这种特殊情况下什么是CompositeKey?
struct my_custom_comp
{
bool operator()( ?? boost::multi_index::composite_key_result<CompositeKey> ?? ) const
{
return blah_blah_blah;
}
};
提前致谢。
答案 0 :(得分:2)
它应该看起来像composite_key_compare
。对于您的情况(非模板版本):
typedef composite_key<
phonebook_entry,
member<phonebook_entry,std::string,&phonebook_entry::family_name>,
member<phonebook_entry,std::string,&phonebook_entry::given_name>
> my_comp_type_t;
struct my_custom_comp
{
bool operator()(
const boost::tuple<const char*>& x,
const boost::multi_index::composite_key_result<my_comp_type_t>& y ) const
{
return false; // should return something instead of false
}
bool operator()(
const boost::multi_index::composite_key_result<my_comp_type_t>& y,
const boost::tuple<const char*>& x ) const
{
return false; // should return something instead of false
}
};