// write some code
}));
This also works with general purpose base::Callback-s and not just base::Clusure-s. What's interesting is that it also supports the good old functor objects and not just lambdas.
The trick is to use the type of the given lambda's operator() method to deduce the signature (search for decltype(&F::operator()) and also store the lambda itself inside of RunnableAdapter instead of a pointer to a function.
Here's a code snippet just in case that somebody is interested. Note that this is an add-on code which does not replace the existing code in any way.
namespace base {
namespace internal {
template <typename F, typename Sig>
class RunnableAdapterFunctor;
template <typename F>
class RunnableAdapter
: public RunnableAdapterFunctor<F, decltype(&F::operator())> {
public:
typedef RunnableAdapterFunctor<F, decltype(&F::operator())> BaseType;
explicit RunnableAdapter(F f) : BaseType(f) {}
};
// Example for Arity 1
template <typename F, typename T, typename R, typename A1>
class RunnableAdapterFunctor<F, R (T::*)(A1) const> {
public:
typedef R (RunType)(A1);
RunnableAdapterFunctor(F f)
: functor_(f) {
}
R Run(typename CallbackParamTraits<A1>::ForwardType a1) {
return functor_(CallbackForward(a1));
}
private:
F functor_;
};
} // namespace internal
} // namespace base