#include #include #include #include #include #include #include #include using namespace std; using namespace boost; template class has_on_method_helper { typedef char no_t; struct yes_t { char _[2]; }; typedef void (H::*MemFn)(const M& msg); template struct sfinae { typedef yes_t type; }; template static typename sfinae<&U::on>::type dispatch(int); template static no_t dispatch(...); public: static const bool value = (sizeof(dispatch(1)) == sizeof(yes_t)); }; // has_on_method_helper template struct has_on_method: public mpl::bool_::value> { }; struct M1 { }; struct M2 { }; struct M3 { }; struct M4 { }; typedef mpl::vector PossibleMessages; struct HandlesM1thruM3 { typedef HandlesM1thruM3 this_type; void on(const M1&); void on(const M2&); void on(const M3&); typedef mpl::remove_if< PossibleMessages , mpl::not_ > >::type MessageList; }; // HandlesM1thruM3 struct HandlesOnlyM2andM4 { typedef HandlesOnlyM2andM4 this_type; void on(const M2&); void on(const M4&); typedef mpl::remove_if< PossibleMessages , mpl::not_ > >::type MessageList; }; // HandlesOnlyM2andM4 struct TypePrinter { template void operator()(U) { cout << ' ' << typeid(U).name(); } }; // TypePrinter int main() { cout << "HandlesM1thruM3::MessageList="; mpl::for_each(TypePrinter()); cout << endl; cout << "HandlesOnlyM2andM4::MessageList="; mpl::for_each(TypePrinter()); cout << endl; } // main