#define USE_RESULT_OF #define BOOST_RESULT_OF_USE_DECLTYPE #include #include #include template struct is_callable; template struct is_callable { typedef char (&pass)[1]; typedef char (&fail)[2]; template struct sub {}; template static pass test(sub, boost::mpl::int_< sizeof(boost::declval()(boost::declval())) >* x = 0); static fail test(...); const static bool value = sizeof(test(sub())) == sizeof(pass); typedef typename boost::mpl::bool_::type type; }; template T const& cref(); template T& ref(); template #ifndef USE_RESULT_OF decltype(F()(cref())) #else typename boost::lazy_enable_if< is_callable, boost::result_of >::type #endif invoke(F f, Arg const& arg) { return f(arg); } template #ifndef USE_RESULT_OF decltype(F()(ref())) #else typename boost::lazy_enable_if< is_callable, boost::result_of >::type #endif invoke(F f, Arg& arg) { return f(arg); } /////////////////////////////////////////////////////////////////////////////// // Client code /////////////////////////////////////////////////////////////////////////////// #include int foo(int& i) { std::cout << i << std::endl; return i; } int main() { int i = 123; invoke(foo, i); }