On Saturday, 10 May 2014 at 10:56:57 UTC, Jacob Carlborg wrote:
I know that there are templates to inspect function parameters,
like ParameterIdentifierTuple and ParameterTypeTuple. But these
don't work for templated/untyped lambdas, they're apparently
not callables. I don't expect ParameterTypeTuple to work, but
it would be nice if ParameterIdentifierTuple and "arity" worked.
Here's an example for clarify:
void foo (alias func) ()
{
alias Types = ParameterTypeTuple!(func);
}
void main ()
{
foo!(x => x * 2);
}
Anyone know if this is fixable or if there's a workaround? I
would like to avoid using hacks like .stringof. I know there's
__parameters as well, but that doesn't work either.
Wasn't there recently a pull request to add TemplateArgsOf, or
something like that. Also, if you know what type the lambda is
going to be instantiated with, you can turn it into a function by
doing:
void foo (alias func) ()
{
alias Types = ParameterTypeTuple!(func!int);
}