On Tuesday, 21 April 2015 at 19:11:43 UTC, John Colvin wrote:
On Tuesday, 21 April 2015 at 19:06:39 UTC, kevin wrote:
enum bool isInputRange = is(typeof(
(inout int = 0)
{
R r = R.init; // can define a range object
if (r.empty) {} // can test for empty
r.popFront(); // can invoke popFront()
auto h = r.front; // can get the front of the range
}));
... is the current implementation in Phobos. But I can't seem
to understand this syntax. What is (inout int = 0)? Why can a
block follow it?
My guess is that this is declaring some sort of function and
testing if it is syntactically valid, but this is still
strange to me.
It's defining a lambda function and checking that it is
*semantically* valid.
No idea what the `(inout int = 0)` is there for, I would have
thought it would be fine without it.
`inout int = 0` is just `inout int n = 0` without the variable
name, which is just `inout int n` with a default argument of 0.