Re: Should range foreach be iterating over an implicit copy?

2012-06-07 Thread Ken
On Friday, 18 May 2012 at 06:17:13 UTC, Lars T. Kyllingstad wrote: On Thursday, 17 May 2012 at 14:18:55 UTC, Steven Schveighoffer wrote: [...] I believe someone has created a byRef struct that wraps a range and iterates it byRef (maybe dsimcha?) Nope, me. :) https://github.com/kyllingstad/lt

Re: Should range foreach be iterating over an implicit copy?

2012-06-07 Thread Ken
On Wednesday, 16 May 2012 at 21:40:39 UTC, Andrei Alexandrescu wrote: On 5/16/12 4:37 PM, Nick Sabalausky wrote: One counter-argument that was raised is that TDPL has an example on page 381 that indicates foreach iterates over an implicit copy. I don't have a copy handy ATM, so I can't look at

Re: Should range foreach be iterating over an implicit copy?

2012-05-17 Thread Lars T. Kyllingstad
On Thursday, 17 May 2012 at 14:18:55 UTC, Steven Schveighoffer wrote: [...] I believe someone has created a byRef struct that wraps a range and iterates it byRef (maybe dsimcha?) Nope, me. :) https://github.com/kyllingstad/ltk/blob/master/ltk/range.d#L12 It only supports the input range prim

Re: Should range foreach be iterating over an implicit copy?

2012-05-17 Thread Jonathan M Davis
On Friday, May 18, 2012 01:04:35 Erik Jensen wrote: > I would be very much in support of having ranges and containers > be distinct, with a standard way to get a range from a container. > Something very similar is done in C#, where containers have a > getEnumerator() method. The enumerator itself h

Re: Should range foreach be iterating over an implicit copy?

2012-05-17 Thread Erik Jensen
On Thursday, 17 May 2012 at 05:48:44 UTC, Nick Sabalausky wrote: - A range is not a collection, it's a *view* of a collection (or of something else). This is a necessary distinction because ranges and collections work in fundamentally different ways: A range is, *by necessity* consumed as it's

Re: Should range foreach be iterating over an implicit copy?

2012-05-17 Thread Jonathan M Davis
On Thursday, May 17, 2012 13:23:22 Steven Schveighoffer wrote: > On Thu, 17 May 2012 11:42:04 -0400, Jonathan M Davis > > wrote: > > On Thursday, May 17, 2012 11:05:46 Steven Schveighoffer wrote: > >> Hm... proposal: > >> > >> foreach(e; ref r) > >> { > >> } > >> > >> equates to your desired co

Re: Should range foreach be iterating over an implicit copy?

2012-05-17 Thread Steven Schveighoffer
On Thu, 17 May 2012 11:42:04 -0400, Jonathan M Davis wrote: On Thursday, May 17, 2012 11:05:46 Steven Schveighoffer wrote: Hm... proposal: foreach(e; ref r) { } equates to your desired code. Would this help? Or you could just do for(; !r.empty; r.popFront()) { auto e = r.front; }

Re: Should range foreach be iterating over an implicit copy?

2012-05-17 Thread Jonathan M Davis
On Thursday, May 17, 2012 11:05:46 Steven Schveighoffer wrote: > Hm... proposal: > > foreach(e; ref r) > { > } > > equates to your desired code. Would this help? Or you could just do for(; !r.empty; r.popFront()) { auto e = r.front; } I really don't think that that's a big deal. I don't t

Re: Should range foreach be iterating over an implicit copy?

2012-05-17 Thread Steven Schveighoffer
On Wed, 16 May 2012 17:37:14 -0400, Nick Sabalausky wrote: A small debate has broken out over on D.learn ( http://forum.dlang.org/thread/jovicg$jta$1...@digitalmars.com#post-jovicg:24jta:241:40digitalmars.com ) that I thought I should move here. Basically, the issue is this: Currently, wh

Re: Should range foreach be iterating over an implicit copy?

2012-05-17 Thread Dmitry Olshansky
On 17.05.2012 18:18, Steven Schveighoffer wrote: On Thu, 17 May 2012 01:48:06 -0400, Nick Sabalausky wrote: I'm a little discouraged that my concern about "input ranges can't save their state, and yet that's exactly what happens implicitly" hasn't been addressed. I was hoping to at least get a

Re: Should range foreach be iterating over an implicit copy?

2012-05-17 Thread Steven Schveighoffer
On Thu, 17 May 2012 01:48:06 -0400, Nick Sabalausky wrote: I'm a little discouraged that my concern about "input ranges can't save their state, and yet that's exactly what happens implicitly" hasn't been addressed. I was hoping to at least get a "That's not really a problem and here's why.

Re: Should range foreach be iterating over an implicit copy?

2012-05-17 Thread bearophile
Nick Sabalausky: One side of the argument is that this behavior is correct and expected since structs are value types, and iterating shouldn't consume the range. In that D.learn thread I've shown that iterating on a fixed-size array, that is a value, doesn't perform a copy of the array. Im

Re: Should range foreach be iterating over an implicit copy?

2012-05-16 Thread Nick Sabalausky
I'm a little discouraged that my concern about "input ranges can't save their state, and yet that's exactly what happens implicitly" hasn't been addressed. I was hoping to at least get a "That's not really a problem and here's why..." However, that said... "Andrei Alexandrescu" wrote... > It i

Re: Should range foreach be iterating over an implicit copy?

2012-05-16 Thread Xinok
On Wednesday, 16 May 2012 at 21:40:39 UTC, Andrei Alexandrescu wrote: On 5/16/12 4:37 PM, Nick Sabalausky wrote: One counter-argument that was raised is that TDPL has an example on page 381 that indicates foreach iterates over an implicit copy. I don't have a copy handy ATM, so I can't look at

Re: Should range foreach be iterating over an implicit copy?

2012-05-16 Thread Era Scarecrow
On Wednesday, 16 May 2012 at 21:37:54 UTC, Nick Sabalausky wrote: A small debate has broken out over on D.learn ( http://forum.dlang.org/thread/jovicg$jta$1...@digitalmars.com#post-jovicg:24jta:241:40digitalmars.com ) that I thought I should move here. Basically, the issue is this: Currently,

Re: Should range foreach be iterating over an implicit copy?

2012-05-16 Thread Andrei Alexandrescu
On 5/16/12 4:37 PM, Nick Sabalausky wrote: One counter-argument that was raised is that TDPL has an example on page 381 that indicates foreach iterates over an implicit copy. I don't have a copy handy ATM, so I can't look at it myself, but I'd love to see Andrei weigh in on this: I'm curious if t

Should range foreach be iterating over an implicit copy?

2012-05-16 Thread Nick Sabalausky
A small debate has broken out over on D.learn ( http://forum.dlang.org/thread/jovicg$jta$1...@digitalmars.com#post-jovicg:24jta:241:40digitalmars.com ) that I thought I should move here. Basically, the issue is this: Currently, when you have a struct-based range, foreach will iterate over a *c