How to get number of parameters in lambda?

Paul Backus snarwin at gmail.com
Tue Mar 9 01:38:52 UTC 2021


On Monday, 8 March 2021 at 23:07:18 UTC, Andrey Zherikov wrote:
> What should I use to get number of lambda arguments? Like get 2 
> for "(arg1, arg2) {}". std.traits.Parameters doesn't work 
> because isCallable returns false.
>
>     alias f = (arg1, arg2) {};
>
>     writeln(isCallable!f);   // prints false
>
>
> Specifying argument types works, e.g. isCallable returns true 
> for (int arg1, int arg2) {}, but I'm looking for a solution for 
> type-less lambdas.

Typeless lambdas are templates, and there's no way to examine the 
arguments of a template function without first instantiating it, 
so I'm afraid you're out of luck.

What's the larger problem you're trying to solve here?


More information about the Digitalmars-d-learn mailing list