static foreach and inline if
monarch_dodra
monarchdodra at gmail.com
Sat Jul 27 10:56:14 PDT 2013
On Saturday, 27 July 2013 at 17:15:54 UTC, JS wrote:
> BTW, it works with static if's, I'm trying to use an inline if
> to reduce redundant code.... since there is no static ?:.
I don't really understand, since you didn't really explain *what*
you were trying to do before pasting that code, but for what it's
worth, there *is* static foreach is supported in D, via
typetuples. Once you are inside a static you can evaluate the arg
statically.
import std.typetuple, std.stdio;
void main()
{
foreach(I; TypeTuple!(0, 1, 2))
{
static if (I == 1)
writeln(I);
}
}
As you can see, this compiles, meaning the if is evaluated at
compile time. Does this help you?
I'm currently working on a static Iota. Details here:
http://d.puremagic.com/issues/show_bug.cgi?id=4085
More information about the Digitalmars-d-learn
mailing list