Comma expressions must die [Was: Reddit: why aren't people using D?]
Jesse Phillips
jessekphillips at gmail.com
Thu Jul 23 20:11:28 PDT 2009
On Thu, 23 Jul 2009 22:56:44 -0400, Adam D. Ruppe wrote:
> 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
Thanks, truth be told I don't know why that first one works. But the
second looks completely reasonable.
More information about the Digitalmars-d
mailing list