#define USE_RESULT_OF //~ #define BOOST_RESULT_OF_USE_DECLTYPE #include #include template T const& cref(); template T& ref(); template #ifndef USE_RESULT_OF decltype(F()(cref())) #else typename 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::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; //~ } struct foo { //~ typedef int result_type; template struct result; template struct result { typedef int type; }; int operator()(int& i) const { std::cout << i << std::endl; return i; } }; int main() { int i = 123; invoke(foo(), i); }