c – 使用基于嵌套值的索引来提升多索引容器
发布时间:2020-12-16 03:24:33 所属栏目:百科 来源:网络整理
导读:如果我有这样的对象: struct Bar { std::string const property();}; 我可以像这样为它创建一个多索引容器: struct tag_prop {};typedef boost::multi_index_container Bar,boost::multi_index::indexed_by boost::multi_index::ordered_non_unique boost:
如果我有这样的对象:
struct Bar { std::string const& property(); }; 我可以像这样为它创建一个多索引容器: struct tag_prop {}; typedef boost::multi_index_container< Bar,boost::multi_index::indexed_by< boost::multi_index::ordered_non_unique< boost::multi_index::tag<tag_prop>,boost::multi_index::const_mem_fun< Bar,const std::string&,&Bar::property > > >,... other indexes > BarContainer; 但如果我有这样一个类: struct Foo { Bar const& bar(); }; 如何在.bar().property()上为Foo对象的容器构造索引? 通常我会嵌入对boost :: bind的调用,但我无法弄清楚如何使它在多索引容器的上下文中工作. 解决方法
我相信你需要创建一个带有两个Foo实例的谓词对象,它的operator()可以在两个实例上调用Foo :: bar().
就像是 struct MyPredicate { bool operator() (const Foo& obj1,const Foo& obj2) const { // fill in here } }; 然后使用 ... boost::multi_index::ordered_unique<boost::multi_index::tag<tag_prop>,boost::multi_index::identity<Foo>,MyPredicate>,... 查看MultiIndex Ordered indices reference (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |