digitalmars.D.learn - Compact Printing of Tuples
- =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= (8/8) Dec 14 2014 Why arent' Tuples defaultly printed as
- Tobias Pankrath (30/38) Dec 14 2014 Tuple.expand?
- bearophile (7/15) Dec 14 2014 I'd like a shorter representation of tuples expecially when you
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
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
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