How to declare an alias to a function literal type
anonymous via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jan 12 08:06:19 PST 2016
On 12.01.2016 16:41, ParticlePeter wrote:
> // alias MF = void function( int i ); // not working
> // alias void function( int i ) MF; // not working
These are both fine. The first one is the preferred style.
>
> MF myFunc;
> myFunc = MF { myCode };
This line doesn't work. Function literals don't take a type before the
curly braces. They have their own syntax. See
http://dlang.org/spec/expression.html (search for "Function Literals").
Since most of the stuff in function literals can be inferred from the
context, something as simple as this works:
myFunc = (i) { myCode };
More information about the Digitalmars-d-learn
mailing list