www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12743] New: tuple printing of alias names


          Issue ID: 12743
           Summary: tuple printing of alias names
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: Phobos
          Assignee: nobody puremagic.com
          Reporter: bearophile_hugs eml.cc

void main() {
    import std.stdio, std.typecons;
    static struct Pair1 { int x, y; }
    auto a1 = [Pair1(1, 2), Pair1(3, 4)];
    alias Pair2 = Tuple!(int, int);
    auto a2 = [Pair2(1, 2), Pair2(3, 4)];
    alias Pair3 = Pair2;
    auto a3 = [Pair3(1, 2), Pair3(3, 4)];

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);

May 13 2014