#define DEFINE_BIND_TYPE(name,expr) \ typedef boost::remove_reference< \ boost::remove_cv
::type>::type name##_expr_type; \ \ struct name:name##_expr_type \ { \ name():name##_expr_type(expr){} \ }; DEFINE_BIND_TYPE( extractor, boost::bind(&std::string::size,boost::bind(&foo::s,_1)))
typedef multi_index_container< foo, indexed_by< hashed_unique<extractor> >
mi_t;
Whether this is more convenient than writing your own key extractors is a debatable issue... One final warning: this trick relies on an undocumented feature of boost::bind, namely that the function objects produced by this lib own a result_type nested typedef, as required by the key extractor concept --otherwise the classes defined by DEFINE_BIND_TYPE wouldn't be conformant key extractors. So, if you want to stand on the documented side you couldn't use this. Also, this is one reason why thes idiom does not extend to boost::lambda expressions.
I've been playing with the problem too, and found this solution...it
does not rely on typeof, but it does rely on return_type. I'm a bit
unsure about why I had to use "unsigned int" to make it work, so I'd
welcome some comments on this.
template
mi_t;
Cheers, Filip