複合キーでmulti_index_containerのカスタム述語の書き方?
-
26-09-2019 - |
質問
私はGoogleで検索し、ブーストの男に検索が、任意の例を見つけることができませんでした。それはとにかく...愚かな質問だかもしれません。
私たちは男性からの有名な電話帳を持っているのでます:
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必要がありますか?私はそれはそれは(原因:)コンパイルエラーに)argumenとして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;
}
};
事前に感謝します。
解決
これは 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
}
};
所属していません StackOverflow