That still won't work. Observe: import std.stdio : writeln;
void main() { writeln(isInputRange!(N)); } class N { N test; //~ bool empty() // oops, we"re not an input range anymore //~ { //~ return false; //~ } @property void popFront() { } @property N front() { return test; } } template isInputRange(R) { enum bool isInputRange = isValidCode!( { R r; // can define a range object if (r.empty) {} // can test for empty r.popFront; // can invoke next auto h = r.front; // can get the front of the range }); } template isValidCode(alias code) { enum bool isValidCode = __traits(compiles, code); } Instead of returning false, it will give out a compiler error. Stanislav Blinov Wrote: > > Andrej Mitrovic wrote: > > > It does look nice. It would look even nicer if __traits gets renamed to > > meta. > > By the way, there's no stopping writing > > template isValidCode(alias code) { enum bool isValidCode = > __traits(compiles, code); } > > :)