Darrell wrote: > Seems when creating your own ranges they can't be a class. > Must be a struct or Segmentation fault (core dumped) will follow. > > This works as long as Test is a struct. > > struct Test > { > @property int front() > { > return 2; > } > > void popFront() > { > } > > enum bool empty = false; > }; > > static assert(isInputRange!Test); > > void mainx(){ > Test x; > writeln(x.take(1)); > }
With classes, you need to create an instance, so (adjusting some of your previous code) this works: import std.range; import std.stdio; class Test { @property int front() { return 2; } void popFront() { } @property bool empty() { return false; } }; static assert(isInputRange!Test); void main(){ ubyte [] p1; Test myTest = new Test(); writeln(myTest.take(1)); }