
Steven Watanabe wrote:
Correct me if I'm wrong, but I think it's not going to work when the inner functor has (T const &) parameter. If my wrapper declares everything T &, then it won't be able to accept non-const rvalues whereas the original functor was able to do that.
If you use forward_adapter, you don't need to handle non-const rvalues. forward_adapter handles the overloading and passes const or non-const lvalues to your function object.
I don't think I follow. Let's say that you have a functor f of type F, where it's legal to call it like this: int n = 5; f(n, 10); //compiles fine f(n, n); /compiles fine You seem to suggest I create my own my_wrapper<F> and define an operator() with only references: template <typename Func> class my_wrapper { ....//ignore the problem of generating multiple operator()'s //for different Func arity template <typename T1, typename T2> /*deduce ret type*/ operator() (T1 & in1, T2 & in2) { //Do something useful here return func_(in1, in2); } }; ... and then wrap it in a forward_adapter: template <typename Func> inline forward_adapter<my_wrapper<Func> > wrap(Func const & in) { return forward_adapter<my_wrapper<Func> >(my_wrapper<Func>(in)); } But now this fails to compile: wrap(f)(n, 10); //Fails, because 10 is passed as int const & whereas this used to compile fine: f(n, 10); What am I missing? Thanks, Andy.