Comma expressions must die [Was: Reddit: why aren't people using D?]

Adam D. Ruppe destructionator at gmail.com
Thu Jul 23 19:56:44 PDT 2009


On Fri, Jul 24, 2009 at 01:38:30AM +0000, Jesse Phillips wrote:
> Thanks for the tutorial, expect to see it on Wiki4D within a year :D

This actually doesn't /quite/ work, since the tuple returned by tuple() has
unnamed fields, which is a different type than the one with named fields.

Gah.

This works though:

auto getPoint() { return Tuple!(int, "x", int, "y")(5, 2); }

That's getting a wee bit ugly even for my likes, but is the best way for
correctness and ease of use on the calling end. Or

Tuple!(int, int) getPoint() { return tuple(5,2); }

That works, but then you have to address the return value as:

auto p = getPoint();
p.field[0] == 5
p.field[1] == 2


Still, easy enough to say:

auto x = p.field[0]; auto y = p.field[1];
x == 5
y == 2



-- 
Adam D. Ruppe
http://arsdnet.net



More information about the Digitalmars-d mailing list