Tuple enhancement
Chris Wright via Digitalmars-d
digitalmars-d at puremagic.com
Sun Oct 16 13:11:01 PDT 2016
On Sun, 16 Oct 2016 18:51:06 +0000, Sebastiaan Koppe wrote:
> On Sunday, 16 October 2016 at 13:58:51 UTC, Andrei Alexandrescu wrote:
>> I was thinking it would be handy if tuples had a way to access a field
>> by name at runtime. E.g.:
>>
>> Tuple!(int, "a", double, "b") t;
>> string x = condition ? "a" : "b";
>> double v = t.get!string(x, 3.14);
>
> That would mean that tuple then needs to keep the strings around -
> taking up space.
It doesn't change Tuple.sizeof.
> That plus the fact that the following code is
> equivalent (obviously):
>
> Tuple!(int, "a", double, "b") t;
> double v = condition ? t.a : t.b;
>
> Why this addition? What does it enable?
It's a little bit of runtime reflection, which people sometimes find
handy. There's nothing stopping you from writing it manually or with
metaprogramming, granted. And if it's just tuples, it doesn't seem like
much of an advantage.
More information about the Digitalmars-d
mailing list