Thread overview | |||||
---|---|---|---|---|---|
|
December 14, 2014 Compact Printing of Tuples | ||||
---|---|---|---|---|
| ||||
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? |
December 14, 2014 Re: Compact Printing of Tuples | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | 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); } |
December 14, 2014 Re: Compact Printing of Tuples | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | 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
|
Copyright © 1999-2021 by the D Language Foundation