how to assign tuple named Tuple easily
Adam D. Ruppe via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Mar 12 17:51:27 PDT 2017
On Monday, 13 March 2017 at 00:02:12 UTC, Inquie wrote:
> I just figured it didn't work in general, but seems to be an
> issue with appending.
Oh, it is because of the implicit construction thing, see my
answer here to learn more:
http://stackoverflow.com/a/42285015/1457000
You can construct the named tuple from a tuple() but you can't
convert one to another since the names change the type.
I don't think the language has a solution with this since you
can't implicit construct nor overload operators on built in
arrays (if it is a custom array, you can do an opOpAssign).
What you could do is
alias ShortName = Tuple!(int, "A");
ShortName[] a;
a ~= ShortName(3);
... of course, at that point, you can also just use a regular
struct too...
More information about the Digitalmars-d-learn
mailing list