Killing the comma operator
Nick Treleaven via Digitalmars-d
digitalmars-d at puremagic.com
Fri May 13 05:44:19 PDT 2016
On Thursday, 12 May 2016 at 02:51:33 UTC, Lionello Lunesu wrote:
> I'm trying to think of a case where changing a single value
> into a tuple with 2 (or more) values would silently change the
> behavior, but I can't think of any. Seems to me it would always
> cause an error, iff the result of the comma operator gets used.
int x,y;
auto f() {return (x=4,y);}
...
auto z = f();
static if (!is(typeof(z) == int)
voteForTrump();
;-)
In practice, this is more plausible with function overloading -
i.e. z.overload() calling a different function. If the comma
operator returns void, the `auto z` line and f().overload() both
fail.
More information about the Digitalmars-d
mailing list