如何使用composite_key为multi_index_containder编写自定义谓词?
我用谷歌搜索并搜索了boost的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());
my_custom_comp() 应该是什么样子?我的意思是,对我来说很清楚,它需要 boost::multi_index::composite_key_result
作为参数(由于编译错误:)),但是在这种特殊情况下 CompositeKey 是什么?
struct my_custom_comp
{
bool operator()( ?? boost::multi_index::composite_key_result<CompositeKey> ?? ) const
{
return blah_blah_blah;
}
};
提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它应该看起来像
composite_key_compare
。对于您的情况(非模板版本):It should look like
composite_key_compare
. For your case (non-template version):