how to assign tuple named Tuple easily

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Mar 13 07:15:05 PDT 2017


On Monday, 13 March 2017 at 14:09:58 UTC, Inquie wrote:
> Yeah, so, surely though we can extract the names from the 
> variable and then supply those like I mentioned?

Yeah, we prolly could, but a simpler thing might be to just use 
typeof:

         Tuple!(int, "A")[] x;
         x ~= typeof(x[0])(3);

> x ~= tuple!x(3)
>
> ? Seems like it would probably be rather trivial with a bit of 
> template code?

Yeah, tuple could certainly adapt to do that too, but I see you 
would write:

> x ~= tuple!typeof(x)(3, 5.0);

and the `tuple!` there is unnecessary: if you already use 
`typeof(x[0])` (you still need a `[0]` in there to get the type 
of the element instead of the array), then you can just construct 
it right there with the next set of parens.


More information about the Digitalmars-d-learn mailing list