#include #include struct A { int get()const{return 0;} int x; }; struct B: public A { }; /* Case 1: Handling of base member functions */ /* Neither of these work typedef boost::multi_index::const_mem_fun< A,int,&A::get > fun_key_t; typedef boost::multi_index::const_mem_fun< B,int,&A::get > fun_key_t; typedef boost::multi_index::const_mem_fun< B,int,&B::get > fun_key_t; */ /* But this does */ typedef boost::multi_index::const_mem_fun_explicit< B,int,int(A::*)()const,&A::get > fun_key_t; /* Case 2: Handling of base member data */ /* We need key_from_key */ template struct key_from_key { public: typedef typename KeyExtractor1::result_type result_type; key_from_key( const KeyExtractor1& key1_=KeyExtractor1(), const KeyExtractor2& key2_=KeyExtractor2()): key1(key1_),key2(key2_) {} template result_type operator()(const Arg& arg)const { return key1(key2(arg)); } private: KeyExtractor1 key1; KeyExtractor2 key2; }; struct B_get_x { typedef int result_type; int operator()(const B& b)const { return b.x; } }; /* key_from_key with identity adds the "chained pointer" capability * to B_get_x. */ typedef key_from_key< B_get_x, boost::multi_index::identity > data_key_t; int main() { B b; fun_key_t key1; data_key_t key2; int i=key1(b); // raw object i=key1(&b); // pointer i=key2(b); // raw object i=key2(&b); // pointer return 0; }