Generators in D

Timon Gehr timon.gehr at gmx.ch
Thu May 12 08:34:27 PDT 2011


> > void genSquares(out int result, int from, int to)
> >          yield!result(x * x);
>
> Wow! i had no idea about this feature! (Variables as template parameters)
> Do we have any documentation, usage example (anything!)? Pretty please.

The argument is an alias, so just a symbol.

See: http://digitalmars.com/d/2.0/template.html (Template Alias Arguments)

The trick is that the template is instantiated as a local function, which has
access to the enclosing scope. (and therewith to the local symbol that is aliased)

Timon


More information about the Digitalmars-d mailing list