Re: foreach with a default range

2015-06-11 Thread Steven Schveighoffer via Digitalmars-d
On 6/11/15 5:06 PM, Jonathan M Davis wrote: On Thursday, 11 June 2015 at 20:54:46 UTC, Steven Schveighoffer wrote: It makes sense, and is very extendable, and uniform. You can deal with this much easier when imlplementing some sort of wrapping than one that has to do something different dependin

Re: foreach with a default range

2015-06-11 Thread Jonathan M Davis via Digitalmars-d
On Thursday, 11 June 2015 at 20:54:46 UTC, Steven Schveighoffer wrote: It makes sense, and is very extendable, and uniform. You can deal with this much easier when imlplementing some sort of wrapping than one that has to do something different depending on how many args are passed inside the []

Re: foreach with a default range

2015-06-11 Thread Steven Schveighoffer via Digitalmars-d
On 6/11/15 4:31 PM, Jonathan M Davis wrote: On Thursday, 11 June 2015 at 13:09:21 UTC, Steven Schveighoffer wrote: On 6/11/15 8:54 AM, Dmitry Olshansky wrote: On 11-Jun-2015 15:22, Steven Schveighoffer wrote: On 6/11/15 4:24 AM, Dmitry Olshansky wrote: Already works. Just define opSlice for

Re: foreach with a default range

2015-06-11 Thread Jonathan M Davis via Digitalmars-d
On Thursday, 11 June 2015 at 13:09:21 UTC, Steven Schveighoffer wrote: On 6/11/15 8:54 AM, Dmitry Olshansky wrote: On 11-Jun-2015 15:22, Steven Schveighoffer wrote: On 6/11/15 4:24 AM, Dmitry Olshansky wrote: Already works. Just define opSlice for container that returns a range and then: fo

Re: foreach with a default range

2015-06-11 Thread Steven Schveighoffer via Digitalmars-d
On 6/11/15 8:54 AM, Dmitry Olshansky wrote: On 11-Jun-2015 15:22, Steven Schveighoffer wrote: On 6/11/15 4:24 AM, Dmitry Olshansky wrote: Already works. Just define opSlice for container that returns a range and then: foreach(elem; container) {} is lowered to: foreach(elem; container[]) {}

Re: foreach with a default range

2015-06-11 Thread Dmitry Olshansky via Digitalmars-d
On 11-Jun-2015 15:22, Steven Schveighoffer wrote: On 6/11/15 4:24 AM, Dmitry Olshansky wrote: Already works. Just define opSlice for container that returns a range and then: foreach(elem; container) {} is lowered to: foreach(elem; container[]) {} I think you want to do opIndex which takes

Re: foreach with a default range

2015-06-11 Thread Steven Schveighoffer via Digitalmars-d
On 6/11/15 4:24 AM, Dmitry Olshansky wrote: Already works. Just define opSlice for container that returns a range and then: foreach(elem; container) {} is lowered to: foreach(elem; container[]) {} I think you want to do opIndex which takes no parameters. opSlice is no longer supposed to b

Re: foreach with a default range

2015-06-11 Thread weaselcat via Digitalmars-d
On Thursday, 11 June 2015 at 08:24:25 UTC, Dmitry Olshansky wrote: On 11-Jun-2015 11:18, w0rp wrote: A thought just came to me. When I'm implementing foreach for a container, I'm left with the choice of using a range for a container or opApply. I've found often that I prefer the ranges, as it's

Re: foreach with a default range

2015-06-11 Thread w0rp via Digitalmars-d
On Thursday, 11 June 2015 at 08:24:25 UTC, Dmitry Olshansky wrote: On 11-Jun-2015 11:18, w0rp wrote: A thought just came to me. When I'm implementing foreach for a container, I'm left with the choice of using a range for a container or opApply. I've found often that I prefer the ranges, as it's

Re: foreach with a default range

2015-06-11 Thread Dmitry Olshansky via Digitalmars-d
On 11-Jun-2015 11:18, w0rp wrote: A thought just came to me. When I'm implementing foreach for a container, I'm left with the choice of using a range for a container or opApply. I've found often that I prefer the ranges, as it's easy for me to write a range that satisfies @nogc @safe pure nothrow

foreach with a default range

2015-06-11 Thread w0rp via Digitalmars-d
A thought just came to me. When I'm implementing foreach for a container, I'm left with the choice of using a range for a container or opApply. I've found often that I prefer the ranges, as it's easy for me to write a range that satisfies @nogc @safe pure nothrow, etc. This is because the range