xxxxxxxxxx
import core.stdc.stdio;
import std.typecons;
import std.stdio;
struct Range{
int x;
bool empty() { return x == 0; }
auto front(){ return x; }
void popFront(){ x--; }
}
struct RangeWrap
{
:
Range range;
this(Range range){ this.range = range; }
auto opApply( int delegate(ref int) op )
{
int result = 0;
foreach(v ; range)
{
result = op(v);
if( result ) break;
}
return result;
}
}
void main()
{
import std.range;
auto range = Range(2);
auto range_wrap = RangeWrap(range);
//foreach(v ; range ) writeln(v); //not safe!
foreach(v ; range_wrap ) writeln(v); //fine, but its a trick.
//iota(0,0).front(); Front is safe, but this go BOOM.
}