Steve Teale wrote:
template isInputRange(R)
{
enum bool isInputRange = is(typeof(
{
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
}()));
}
I can not possibly be the only D enthusiast who finds this completely incomprehensible.
Yeah, that one is a bit tricky, and what makes it worse is that it seems
officially sanctioned by Walter/Andrei as the "right way" to check if a
type supports some operations. Basically, if you have:
is(typeof({ @@@ }()));
this means "if I made a function containing @@@, would that function
compile?". It's a hack which stems from the way the is expression works.
What is a range?
As others have mentioned, it's just a struct (or other type) that
happens to support certain operations.