Bug 12743 – tuple printing of alias names

Status
REOPENED
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2014-05-13T10:23:09Z
Last change time
2024-12-01T16:21:10Z
Assigned to
No Owner
Creator
bearophile_hugs
See also
https://issues.dlang.org/show_bug.cgi?id=3248
Moved to GitHub: phobos#10054 →

Comments

Comment #0 by bearophile_hugs — 2014-05-13T10:23:09Z
void main() { import std.stdio, std.typecons; static struct Pair1 { int x, y; } auto a1 = [Pair1(1, 2), Pair1(3, 4)]; a1.writeln; alias Pair2 = Tuple!(int, int); auto a2 = [Pair2(1, 2), Pair2(3, 4)]; a2.writeln; alias Pair3 = Pair2; auto a3 = [Pair3(1, 2), Pair3(3, 4)]; a3.writeln; } Outout with DMD 2.066alpha: [Pair1(1, 2), Pair1(3, 4)] [Tuple!(int, int)(1, 2), Tuple!(int, int)(3, 4)] [Tuple!(int, int)(1, 2), Tuple!(int, int)(3, 4)] But I'd like an output like this, is it possible? [Pair1(1, 2), Pair1(3, 4)] [Pair2(1, 2), Pair2(3, 4)] [Pair3(1, 2), Pair3(3, 4)] If that's not possible then we could add a tuple alternative constructor that accepts the name (similar to Python collections.namedtuple), used only by write/format to print a nice tuple name: alias Pair4 = NamedTuple!("Pair4", int, int);
Comment #1 by andrej.mitrovich — 2014-05-13T12:48:46Z
*** This issue has been marked as a duplicate of issue 9593 ***
Comment #2 by bearophile_hugs — 2014-05-13T16:44:19Z
(In reply to Andrej Mitrovic from comment #1) > > *** This issue has been marked as a duplicate of issue 9593 *** Reopened because they are two quite different issues. In Issue 9593 I've asked for a way to avoid the printing of the tuple type with a formatting string using "-": writefln("%-s", data[0]); ==> ("Fred", 5) writefln("%-(%s %)", data); ==> ("Fred", 5) ("Bob", 10) ("Mark", 30) While in this issue I have suggested to print the alias name (or to introduce a NamedTuple): alias Pair2 = Tuple!(int, int); auto a2 = [Pair2(1, 2), Pair2(3, 4)]; a2.writeln; ==> [Pair2(1, 2), Pair2(3, 4)]
Comment #3 by andrej.mitrovich — 2014-05-13T18:17:21Z
(In reply to bearophile_hugs from comment #2) > (In reply to Andrej Mitrovic from comment #1) > > > > *** This issue has been marked as a duplicate of issue 9593 *** > > Reopened because they are two quite different issues. Either way please start making pull requests. Making a 1000 subtly-different enhancement requests isn't helping anyone.
Comment #4 by robert.schadek — 2024-12-01T16:21:10Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10054 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB