Static loops

Tofu Ninja emmons0 at purdue.edu
Sat Feb 15 00:39:24 PST 2014


To me it seems odd that we have a static if but no static while 
or static for or static foreach.

Basicly all a static loop would do is unroll itself at compile 
time. The only reason I want this is that currently it is 
impossible to use a loop variable in any sort of complietime 
expression such as a static if or a template instantiation.

Was/is something like this planned? Is there a way to get similar 
functionality now? So far the only way I have found to insert 
loop variables into a compile time expression is to use a side 
function to do looping and generate a string for mixins, which is 
very very very ugly, am I missing somthing?


I saw one thread from 2004 about the same thing with very little 
replies...
http://forum.dlang.org/thread/c7hjcc$2hph$1@digitaldaemon.com

[Edit]
Ok before I posted this, I did a few more tests and it seems like 
foreach has this capability somewhat, which is just confusing. 
Using foreach on a tuple causes it to be evaluated at compile 
time, which is nice but confusing. Come to think of it, I don't 
know how you would loop over tuples otherwise...


More information about the Digitalmars-d mailing list