www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Compact Printing of Tuples

reply =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= <per.nordlow gmail.com> writes:
Why arent' Tuples defaultly printed as

(1, 2)

instead

Tuple!(int, int)(1, 2)

?

What's the most convenient of tweak this behaviour so I get 
untyped-printing. Is there a function to convert a Tuple to into 
a D parameter tuple?
Dec 14 2014
next sibling parent "Tobias Pankrath" <tobias pankrath.net> writes:
On Sunday, 14 December 2014 at 11:53:21 UTC, Nordlöw wrote:
 Why arent' Tuples defaultly printed as

 (1, 2)

 instead

 Tuple!(int, int)(1, 2)

 ?

 What's the most convenient of tweak this behaviour so I get 
 untyped-printing. Is there a function to convert a Tuple to 
 into a D parameter tuple?
Tuple.expand? template Wrapper(Tuple) { static if(isTuple!Tuple) { struct Wrapper(Tuple) { Tuple tup; alias tup this; // should use a better overload string toString() { auto app = appender!string(); app.put("("); app.put(to!string(wrapper(tuple[0]))); foreach(t; tuple.expand[1 .. $]) { app.put(", "); app.put(to!string(wrapper(t)))) } app.put(")"); return app.data; } } } else alias Wrapper = Tuple; } auto wrapper(T)(T t) { return Wrapper!T(t); }
Dec 14 2014
prev sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
Nordlöw:

 Why arent' Tuples defaultly printed as

 (1, 2)

 instead

 Tuple!(int, int)(1, 2)

 ?

 What's the most convenient of tweak this behaviour so I get 
 untyped-printing. Is there a function to convert a Tuple to 
 into a D parameter tuple?
I'd like a shorter representation of tuples expecially when you have an array of them. A single tuple is acceptable to print it in the longer current form. You can open an enhancement request. Bye, bearophile
Dec 14 2014