opApply not called for foeach(container)

2012-07-11 Thread monarch_dodra
If you create a class/struct that can give you a (forward) range via "opSlice()", and that range gives you access to "opApply", then you get two different behaviors: MyClass arr = ...; foreach(a; arr) ... foreach(a; arr[]) ... In the first case, foreach will call opSlice(), a

Re: opApply not called for foeach(container)

2012-07-11 Thread Christophe Travert
"monarch_dodra" , dans le message (digitalmars.D:171868), a écrit : > I'm wondering if this is the correct behavior? In particular, > since foreach guarantees a call to opSlice(), so writing "arr[]" > *should* be redundant, yet the final behavior is different. > > That said, the "issue" *could*

Re: opApply not called for foeach(container)

2012-07-11 Thread monarch_dodra
On Wednesday, 11 July 2012 at 14:10:35 UTC, trav...@phare.normalesup.org (Christophe Travert) wrote: I think foreach should never call opSlice. That's not in the online documentation (http://dlang.org/statement.html#ForeachStatement), unless I missed something. If you want to use foreach on a cl

Re: opApply not called for foeach(container)

2012-07-11 Thread kenji hara
I think the online documentation (http://dlang.org/statement.html#ForeachStatement) is not sufficient. foreach (e; aggr) { ...body...} Current dmd translates above foreach statement like follows. 1. If aggr has opApply or opApplyReverse, it's used. 2. If aggr has empty/front/popFront: 2a. If a

Re: opApply not called for foeach(container)

2012-07-11 Thread Christophe Travert
"monarch_dodra" , dans le message (digitalmars.D:171902), a écrit : > I just re-read the docs you linked to, and if that was my only > source, I'd reach the same conclusion as you. I think the reference spec for D should be the community driven and widely available website, not a commercial book

Re: opApply not called for foeach(container)

2012-07-11 Thread Jonathan M Davis
On Wednesday, July 11, 2012 14:10:35 Christophe Travert wrote: > "monarch_dodra" , dans le message (digitalmars.D:171868), a écrit : > > I'm wondering if this is the correct behavior? In particular, > > since foreach guarantees a call to opSlice(), so writing "arr[]" > > *should* be redundant, yet

Re: opApply not called for foeach(container)

2012-07-11 Thread Jonathan M Davis
On Wednesday, July 11, 2012 15:43:13 Christophe Travert wrote: > "monarch_dodra" , dans le message (digitalmars.D:171902), a écrit : > > I just re-read the docs you linked to, and if that was my only > > source, I'd reach the same conclusion as you. > > I think the reference spec for D should be t

Re: opApply not called for foeach(container)

2012-07-12 Thread monarch_dodra
On Wednesday, 11 July 2012 at 20:24:42 UTC, Jonathan M Davis wrote: The problem is that it's essentially spread out across 3 places: the online spec, TDPL, and the compiler. ... - Jonathan M Davis The problem is not only the documentation, it's getting authoritative answers. I see some stra

Re: opApply not called for foeach(container)

2012-07-12 Thread Timon Gehr
On 07/12/2012 04:50 PM, monarch_dodra wrote: On Wednesday, 11 July 2012 at 20:24:42 UTC, Jonathan M Davis wrote: The problem is that it's essentially spread out across 3 places: the online spec, TDPL, and the compiler. ... - Jonathan M Davis The problem is not only the documentation, it's ge

Re: opApply not called for foeach(container)

2012-07-12 Thread Steven Schveighoffer
On Wed, 11 Jul 2012 11:10:16 -0400, kenji hara wrote: I think the online documentation (http://dlang.org/statement.html#ForeachStatement) is not sufficient. foreach (e; aggr) { ...body...} Current dmd translates above foreach statement like follows. 1. If aggr has opApply or opApplyReverse,

Re: opApply not called for foeach(container)

2012-07-12 Thread monarch_dodra
On Thursday, 12 July 2012 at 21:18:21 UTC, Steven Schveighoffer wrote: If opSlice is to be used, this is how it should go (in order of precedence): 1. if aggr has opApply or opApplyReverse, use it. 2. if aggr has opSlice, and the result of aggr.opSlice() has opApply or opApplyReverse, use i

Re: opApply not called for foeach(container)

2012-07-12 Thread Steven Schveighoffer
On Thu, 12 Jul 2012 17:35:23 -0400, monarch_dodra wrote: On Thursday, 12 July 2012 at 21:18:21 UTC, Steven Schveighoffer wrote: If opSlice is to be used, this is how it should go (in order of precedence): 1. if aggr has opApply or opApplyReverse, use it. 2. if aggr has opSlice, and the

Re: opApply not called for foeach(container)

2012-07-12 Thread monarch_dodra
On Thursday, 12 July 2012 at 22:02:19 UTC, Steven Schveighoffer wrote: On Thu, 12 Jul 2012 17:35:23 -0400, monarch_dodra wrote: On Thursday, 12 July 2012 at 21:18:21 UTC, Steven Schveighoffer wrote: If opSlice is to be used, this is how it should go (in order of precedence): 1. if aggr h

Re: opApply not called for foeach(container)

2012-07-13 Thread Steven Schveighoffer
On Fri, 13 Jul 2012 02:20:45 -0400, monarch_dodra wrote: On Thursday, 12 July 2012 at 22:02:19 UTC, Steven Schveighoffer wrote: On Thu, 12 Jul 2012 17:35:23 -0400, monarch_dodra wrote: On Thursday, 12 July 2012 at 21:18:21 UTC, Steven Schveighoffer wrote: If opSlice is to be used, thi

Re: opApply not called for foeach(container)

2012-07-15 Thread Jonathan M Davis
On Thursday, July 12, 2012 16:50:22 monarch_dodra wrote: > On Wednesday, 11 July 2012 at 20:24:42 UTC, Jonathan M Davis > > wrote: > > The problem is that it's essentially spread out across 3 > > places: the online > > spec, TDPL, and the compiler. > > > > ... > > > > - Jonathan M Davis > > The

Re: opApply not called for foeach(container)

2012-07-15 Thread Mehrdad
On Sunday, 15 July 2012 at 20:01:35 UTC, Jonathan M Davis wrote: Ideally, we wouldn't even need opApply anymore AFAIT, that's impossible. Not because of D, but because of other stuff. Lots of functions require callbacks for enumeration (e.g. EnumChildWindows in Windows); it's simply impossib

Re: opApply not called for foeach(container)

2012-07-16 Thread David Nadlinger
On Monday, 16 July 2012 at 06:27:13 UTC, Mehrdad wrote: On Sunday, 15 July 2012 at 20:01:35 UTC, Jonathan M Davis wrote: Ideally, we wouldn't even need opApply anymore AFAIT, that's impossible. Not because of D […] How else woud you implement things like parallel foreach, …? David

Re: opApply not called for foeach(container)

2012-07-16 Thread Jonathan M Davis
On Monday, July 16, 2012 09:47:50 David Nadlinger wrote: > On Monday, 16 July 2012 at 06:27:13 UTC, Mehrdad wrote: > > On Sunday, 15 July 2012 at 20:01:35 UTC, Jonathan M Davis wrote: > >> Ideally, we wouldn't even need opApply anymore > > > > AFAIT, that's impossible. > > > > Not because of D […

Re: opApply not called for foeach(container)

2012-07-16 Thread David Nadlinger
On Monday, 16 July 2012 at 08:13:49 UTC, Jonathan M Davis wrote: On Monday, July 16, 2012 09:47:50 David Nadlinger wrote: On Monday, 16 July 2012 at 06:27:13 UTC, Mehrdad wrote: > AFAIT, that's impossible. > > Not because of D […] How else woud you implement things like parallel foreach, …?