On Monday, 7 March 2016 at 18:21:24 UTC, Meta wrote:
On Monday, 7 March 2016 at 10:40:15 UTC, ZombineDev wrote:
Which I don't think will cause ambiguity with delegates:
auto tuple3 = { getInt() }; tuple
auto tuple3 = { getInt(); }; lambda
Unfortunately this will not work. There was a tuple proposal
sometime back in 2012 or 2013. I can't remember the exact
reason, but somebody came up with a case where it can be
ambiguous as to whether it's a tuple or a delegate.
I believe it was the empty tuple, which is indistinguishable from
a do-nothing lambda.
pragma(msg, typeof({}));
// prints:
// void function() pure nothrow @nogc @safe
Nothing that can't be solved, I'd say. Just define `{}` to mean
one of them and provide a workaround for the other one.
OTOH, distinguishing between tuples and lambdas requires
unlimited lookahead and backtracking, which can become expensive
for pathological cases.