Re: Formatted output of range of tuples

2014-10-13 Thread Sag Academy via Digitalmars-d-learn
On Monday, 13 October 2014 at 09:20:27 UTC, monarch_dodra wrote: 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

Re: Formatted output of range of tuples

2014-10-13 Thread monarch_dodra via Digitalmars-d-learn
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 th

Re: Formatted output of range of tuples

2014-10-13 Thread bearophile via Digitalmars-d-learn
Ali Çehreli: foreach (i, element; MyRange(42).enumerate) { // ... } versus sequence!"n" and zip: foreach (i, element; zip(sequence!"n", MyRange(42))) { // ... } But it's better to not use automatic unpacking of tuples. See issues 7361 and especially 9817. B

Re: Formatted output of range of tuples

2014-10-12 Thread Ali Çehreli via Digitalmars-d-learn
On 10/08/2014 02:31 PM, bearophile wrote: > For indexes now there is also "enumerate". > > Bye, > bearophile Thanks for the tip. std.range.enumerate makes a big difference: foreach (i, element; MyRange(42).enumerate) { // ... } versus sequence!"n" and zip: foreach (i, elem

Re: Formatted output of range of tuples

2014-10-08 Thread bearophile via Digitalmars-d-learn
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. Bye, bearophile

Re: Formatted output of range of tuples

2014-10-08 Thread antropod via Digitalmars-d-learn
On Wednesday, 8 October 2014 at 21:34:54 UTC, anonymous wrote: You can turn the tuples into ranges with `only`: writef("%(%(%s %)\n%)", zip(indexes, source).map!(t => only(t.expand))); That works for me, thanks. By the way my compiler is DMD 2.066.0

Re: Formatted output of range of tuples

2014-10-08 Thread Ali Çehreli via Digitalmars-d-learn
On 10/08/2014 02:34 PM, anonymous wrote: > You can turn the tuples into ranges with `only`: > > writef("%(%(%s %)\n%)", zip(indexes, source).map!(t => > only(t.expand))); I haven't measured the performance but there is also the following automatic expansion of tuple members as slice elements:

Re: Formatted output of range of tuples

2014-10-08 Thread bearophile via Digitalmars-d-learn
antropod: Looks fairly straightforward. But, the second function causes compilation error: std.format.FormatException@C:\D\dmd2\windows\bin\..\..\src\phobos\std\format.d(2 585): Expected '%s' format specifier for type 'Tuple!(uint, uint)' Can you help me with that? Currently the "%(%s%)"

Re: Formatted output of range of tuples

2014-10-08 Thread anonymous via Digitalmars-d-learn
On Wednesday, 8 October 2014 at 21:21:47 UTC, antropod wrote: Hello! Consider this code: +++ import std.stdio; import std.range; import std.algorithm; void printIndexedArray1(T, Range)(T[] source, Range indexes) { foreach(row; zip(indexes, source)) { foreach(col

Formatted output of range of tuples

2014-10-08 Thread antropod via Digitalmars-d-learn
Hello! Consider this code: +++ import std.stdio; import std.range; import std.algorithm; void printIndexedArray1(T, Range)(T[] source, Range indexes) { foreach(row; zip(indexes, source)) { foreach(col; row) { write(col, " ");