How to declare an alias to a function literal type
Marc Schütz via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jan 12 09:28:35 PST 2016
On Tuesday, 12 January 2016 at 16:55:48 UTC, ParticlePeter wrote:
> I can rewrite the definition of otherFunc like this:
> void otherFunc( MF mf );
>
> But I cannot pass an anonymous function to otherFunc like this:
> otherFunc( MF { myCode; } );
>
> Thats what I want. Any working example?
If I understand you correctly (not sure), you would like to write
`MF` so that you don't need to specify the parameters in the
lambda? That's not possible, because the code inside the lambda
needs names for them if it wants to access them, but parameter
names are _not_ part of the function type, and therefore the
alias doesn't know about them.
However, you don't need to specify the full parameter list in the
lambda, the names and `ref` are enough:
otherFunc( (ref a, ref b, ref c) { /* use a, b, c */ } );
More information about the Digitalmars-d-learn
mailing list