On 02/07/12 18:57, kenji hara wrote:
D does not provide index for the range iteration.
Instead, you can create 'zipped' range.
Oh, cool. That's a nice feature that I can think of other uses for ... :-)
On 02/07/12 18:43, bearophile wrote:
It's not a bug, it's caused by how ranges like retro work. retro yields a single
item. In D you can't overload on return values, so foreach can't try to call a
second retro.front overload that yields an (index,item) tuple (that later
foreach is able to unpack
"bearophile" , dans le message (digitalmars.D:171013), a écrit :
> It's not a bug, it's caused by how ranges like retro work. retro
> yields a single item. In D you can't overload on return values,
But you can overload OpApply.
--
Christophe
D does not provide index for the range iteration.
Instead, you can create 'zipped' range.
void main() {
auto intr = sequence!"n"(); // 0, 1, 2, ...
double[] a = [ 0, 1, 2, 3, 4, 5 ];
foreach(i, x; zip(intr, retro(a)))
writeln(i, "\t", x);
}
zip(intr, retro(a)) is a
On Monday, 2 July 2012 at 16:49:06 UTC, Joseph Rushton Wakeling
wrote:
On 02/07/12 17:48, Timon Gehr wrote:
What would be your expected output?
I'd expect to see
0 5
1 4
2 3
3 2
4 1
5 0
i.e. as if I was foreach-ing over an array with the same values
in inverted order
On 02/07/12 17:48, Timon Gehr wrote:
What would be your expected output?
I'd expect to see
0 5
1 4
2 3
3 2
4 1
5 0
i.e. as if I was foreach-ing over an array with the same values in inverted
order.
Joseph Rushton Wakeling:
double[] a = [ 0, 1, 2, 3, 4, 5 ];
foreach(i, x; retro(a))
writeln(i, "\t", x);
It's not a bug, it's caused by how ranges like retro work. retro
yields a single item. In D you can't overload on return values,
so foreach can't try to call a se
What would be your expected output?
From the inner to the outer expression:
First the range is reversed and then the elements of this range
are enumerated.
On 07/02/2012 05:36 PM, Joseph Rushton Wakeling wrote:
Hello all,
A problem with the retro function from std.range -- although it
apparently operates on a bidirectional range, it fails when used with
foreach requesting both value and index. Running this code:
//
Running this code
Sorry, should be "attempting to compile this code".
Hello all,
A problem with the retro function from std.range -- although it apparently
operates on a bidirectional range, it fails when used with foreach requesting
both value and index. Running this code:
import std.range, std.stdio;
void mai
11 matches
Mail list logo