Imagine following toy example of templated lambda:
auto f = []<typename T>(){};
The shortest way I know to call this lambda for int
type is f.operator()<int>();
.
Does anybody know if there is simpler/shorter syntax for calling templated lambda?
Of cause f<int>();
doesn't compile, but would be nice to have such syntax similar to template function call.
But maybe in C++ standard they invented for lambda some special shortcut alias that I don't know about, like f._<int>();
, here imaginary _
is a name of method that just perfect-forwards all args to .operator()
method. Is there anything like that? Or maybe f.call<int>()
?
I understand that lambda behaves like simple functor class with method .operator()
, hence same long call syntax as for templated functor f.operator()<int>()
. But in your custom functor you can invent alias method _
that forwards args, is there such similar alias in lambda?
As @RedFog told it is possible to implement a helper function that you use like call<int>(f);
but I don't know how to implement such function for very general case - imagine if lambda has a mix of typename
and auto
params, like []<typename A, auto B, typename Q>{};
, I don't know how to write very generic helper function for such mixed case.