A Perspective on D from game industry
John Colvin via Digitalmars-d
digitalmars-d at puremagic.com
Tue Jun 17 07:00:43 PDT 2014
On Tuesday, 17 June 2014 at 13:52:48 UTC, Dicebot wrote:
> On Tuesday, 17 June 2014 at 13:36:48 UTC, John Colvin wrote:
>> also, foreach that works outside of function scope would be
>> awesome:
>>
>> mixin template A(TL ...)
>> {
>> foreach(i, T; TL)
>> {
>> mixin("T v" ~ i.to!string);
>> }
>> }
>
> It is not "also", it is primary use case of static foreach
I though the primary use of static foreach was to force the
compiler to attempt compile-time iteration even for
non-TemplateArgList arguments like arrays known at compile-time
e.g.
static foreach(el; [1,2,3,4])
{
pragma(msg, el);
}
or
static foreach(el; 5 .. 8)
{
pragma(msg, el);
}
The mixin template example I gave is already a "static" foreach,
just not explicitly so.
More information about the Digitalmars-d
mailing list