CTFE Status
Stefan Koch via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jan 26 09:06:56 PST 2017
Member-Function calls work now!
this code will compile and properly execute with newCTFE:
struct iota_range
{
int current;
int end;
int step;
uint front()
{
return current;
}
void popFront()
{
current += step;
// we need this return otherwise we generate invalid code :(
return ;
}
bool empty()
{
return current > end;
}
this(uint end, uint begin = 0, uint step = 1) pure
{
assert(step != 0, "cannot have a step of 0");
this.step = step;
this.current = begin;
this.end = end;
}
}
auto Iota(int end)
{
return iota_range(end);
}
uint testThisCall(uint end)
{
uint result;
foreach(n;Iota(end))
{
result += n;
}
return result;
}
static assert(testThisCall(12) == 78);
Neat, huh ?
More information about the Digitalmars-d
mailing list