Formatted output of range of tuples

monarch_dodra via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Oct 13 02:20:26 PDT 2014


On Wednesday, 8 October 2014 at 23:28:34 UTC, bearophile wrote:
> anonymous:
>
>> You can turn the tuples into ranges with `only`:
>>
>> writef("%(%(%s %)\n%)", zip(indexes, source).map!(t => 
>> only(t.expand)));
>
> This is a nice idea. Expand can probably be replaced by a []. I 
> presume this works only if the types inside the tuple are the 
> same.

Expand creates "returns" a TypeTuple though, so it's arguably 
"free". "[]" allocates a dynamic array, so is costly.

On the flip side, "only" is *entirelly* by value, and carries all 
its arguments. If the tuple is big, then the range can become 
quite big.


More information about the Digitalmars-d-learn mailing list