Firstly,
template <typename IMPL, typename RET> RET call (functor <IMPL> func, IMPL * impl) { return func.call (impl); }
really should be
template <typename RET, typename IMPL> RET call (functor <IMPL> func, IMPL * impl) { return func.call (impl); }
(I inverted RET and IMPL in the template argument list) so that you can call a function like
call<int>(f, impl);
instead of typing
call<impl_type, int>(f, impl);
In fact, the compiler cannot output RET , so you must provide it yourself.
Secondly, you do not need to overload void , since it is normal to return a void expression. If you want, you can add overload:
template <typename IMPL> void call(functor<IMPL> func, IMPL* impl)
and use call(f, impl) when calling this overload.
If you have access to C ++ 0x, consider using decltype .
source share