digitalmars.D.learn - foreach_reverse error
- "ixid" <nuaccount gmail.com> May 09 2012
- Timon Gehr <timon.gehr gmx.ch> May 09 2012
- Timon Gehr <timon.gehr gmx.ch> May 09 2012
- mta`chrono <chrono mta-international.net> May 11 2012
- "ixid" <nuaccount gmail.com> May 09 2012
- "H. S. Teoh" <hsteoh quickfur.ath.cx> May 09 2012
- "bearophile" <bearophileHUGS lycos.com> May 09 2012
- "Steven Schveighoffer" <schveiguy yahoo.com> May 11 2012
With this code foreach works but foreach_reverse does not:
void main()
{ int[] ints = [2,2,2,5,5,5,4,4,4];
auto temp = group(ints);
foreach_reverse(i;temp)
i[1].writeln;
}
Is this a known issue? Is there a sensible reason for this?
May 09 2012
On 05/09/2012 10:50 PM, ixid wrote:With this code foreach works but foreach_reverse does not: void main() { int[] ints = [2,2,2,5,5,5,4,4,4]; auto temp = group(ints); foreach_reverse(i;temp) i[1].writeln; } Is this a known issue? Is there a sensible reason for this?
group returns a lazy forward range. use foreach(i; group(retro(ints)))
May 09 2012
On 05/09/2012 11:33 PM, ixid wrote:Thanks, sorry to have not understand such a basic point, it's rather hard to get to grips with everything like this in D.
No worries.
May 09 2012
group returns a lazy forward range. use foreach(i; group(retro(ints)))
Yet another reason foreach_reverse needs to go. T
No please don't! There are hundred and ten very usefull cases.
May 11 2012
Thanks, sorry to have not understand such a basic point, it's rather hard to get to grips with everything like this in D.
May 09 2012
On Wed, May 09, 2012 at 11:09:15PM +0200, Timon Gehr wrote:On 05/09/2012 10:50 PM, ixid wrote:With this code foreach works but foreach_reverse does not: void main() { int[] ints = [2,2,2,5,5,5,4,4,4]; auto temp = group(ints); foreach_reverse(i;temp) i[1].writeln; } Is this a known issue? Is there a sensible reason for this?
group returns a lazy forward range. use foreach(i; group(retro(ints)))
Yet another reason foreach_reverse needs to go. T -- It only takes one twig to burn down a forest.
May 09 2012
H. S. Teoh:Yet another reason foreach_reverse needs to go.
Nope, the specific kind of range of group not being what the OP desired is not foreach_reverse fault. Bye, bearophile
May 09 2012
On Fri, 11 May 2012 03:43:53 -0400, mta`chrono <chrono mta-international.net> wrote:group returns a lazy forward range. use foreach(i; group(retro(ints)))
Yet another reason foreach_reverse needs to go. T
No please don't! There are hundred and ten very usefull cases.
No, there is only one. foreach_reverse(i; 0..10) {...} Every other usage of foreach_reverse can be rewritten with foreach. I would argue that this should work: foreach(i; 10..0) but it would be quite odd given that you would start with 9 and end with 0. I don't have a really good answer for this, foreach(i; 9..-1) isn't really acceptable, especially if i is unsigned. -Steve
May 11 2012









Timon Gehr <timon.gehr gmx.ch> 