xxxxxxxxxx
struct SimpleRange
{
this(int[] front) { this.front = front; }
bool empty = false;
int[] front;
int i = 0;
void popFront()
in (!empty)
{
// front ~= [ ];
front[0] = 0;
if (++i == 2) empty = true;
}
}
void main()
{
import std.conv : to;
import std.meta : aliasSeqOf;
import std.range : array;
// aliasSeqOf uses static foreach!
int[][] r1 = [ aliasSeqOf!(SimpleRange([1, 1])) ];
int[][] r2 = SimpleRange([1, 1]).array;
assert(r1 == r2, r1.to!string ~ " != " ~ r2.to!string);
string result1 = "";
static foreach (x; SimpleRange([1, 1]))
{
result1 ~= x.to!string;
}
string result2 = "";
foreach (x; SimpleRange([1, 1]))
{
result2 ~= x.to!string;
}
assert(result1 == result2, result1.to!string ~ " != " ~ result2.to!string);
}