1

我用谷歌搜索了boost的人,但没有找到任何例子。可能这是一个愚蠢的问题......无论如何。

所以我们有这个人的著名电话簿:

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;
    }
};

提前致谢。

4

1 回答 1

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
    }
};
于 2010-06-10T12:31:53.543 回答