[Issue 4666] Optional name for std.typecons.Tuples?

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Oct 16 15:35:37 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4666



--- Comment #3 from bearophile_hugs at eml.cc 2010-10-16 15:34:55 PDT ---
It's important to give a good textual representation to Tuples, to avoid a very
cluttered textual output. On the other hand defining a printing function to
print tuples is not so natural.

So an alternative solution is to give each Tuple a mutable static string
argument, that for a Tuple defined as:
Tuple!(double, "x", double, "y")

gets automatically initialized to something like:
"Tuple!(double,\"x\",double,\"y\")"

But later may be modified by the programmer to something different. The tuple
toString may just always prepend this string to the textual representation of
the Tuple.

Allowing something like this:


void main() {
import std.stdio: writeln;
import std.typecons: Tuple;
void main() {
    alias Tuple!(double, "x", double, "y") Point;
    writeln(p.__name); // prints: Tuple!(double,"x",double,"y")
    auto p = Point(1, 2);
    writeln(p); // prints: Tuple!(double,"x",double,"y")(1, 2)
    Point.__name = "Point";
    writeln(p.__name); // prints: Point    
    writeln(p); // prints: Point(1, 2)
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list