The One-Letter Nested Function - a sample article for some kind of

bearophile bearophileHUGS at lycos.com
Mon Feb 13 06:14:38 PST 2012


Zach the Mystic:

> void setRandomColorPair( ref ColorPair cp )
> {
>     import std.random;
>     ubyte u(int a, int b) { return cast(ubyte) uniform(a,b); }

Where possible it's good to add "static" to nested functions:

static ubyte u(in int a, in int b) pure nothrow { return cast(ubyte) uniform(a,b); }

-----------------

Andrej Mitrovic:

> It would be better if you didn't have to specify the argument types. I
> think bear asked for templated lambdas, so this could eventually
> become:

Some related requests (one and half of them is by me):
http://d.puremagic.com/issues/show_bug.cgi?id=7357
http://d.puremagic.com/issues/show_bug.cgi?id=7308
http://d.puremagic.com/issues/show_bug.cgi?id=7176

Bye,
bearophile


More information about the Digitalmars-d mailing list