mercredi 1 avril 2020

How to get return type and parameter type of a generic lambda?

I want to get return type and parameter type of a lambda. Is it possible to figure out the parameter type and return type of a lambda?give a solution.But it does not work for generic lambda.

template<typename F>
struct function_traits :public
    function_traits<decltype(&F::operator())> {};

template<typename R,typename C,typename... Args>
struct function_traits<R(C::*)(Args...)const>:public
    function_traits<R(Args...)>{
  constexpr static size_t arity = sizeof...(Args);
};

auto f1 = [](int x) {return x+1; };
Print(function_traits<decltype(f1)>::arity);  //return 1
auto f2 = [](auto x) {return x+1; };
Print(function_traits<decltype(f2)>::arity);  //error

So how to solve it to get return type and parameter type of a generic lambda?

Aucun commentaire:

Enregistrer un commentaire