Re: Is there any reason to use non-ref foreach?

2018-09-04 Thread Dukc via Digitalmars-d-learn
On Tuesday, 4 September 2018 at 08:17:14 UTC, Andrea Fontana wrote: Waiting for this to be merged: https://github.com/dlang/dmd/pull/8437 Well, it seems Andrei has already approved the concept. well, THAT is a good reason to avoid this paradigm. Thanks for the info.

Re: Is there any reason to use non-ref foreach?

2018-09-04 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 4 September 2018 at 07:06:43 UTC, Dukc wrote: On Monday, 3 September 2018 at 13:34:36 UTC, Andrea Fontana wrote: On Friday, 31 August 2018 at 09:59:20 UTC, Dukc wrote: For me, it seems that for generality you should always add ref into foreach loop variable. The reason is this:

Re: Is there any reason to use non-ref foreach?

2018-09-04 Thread Dukc via Digitalmars-d-learn
On Monday, 3 September 2018 at 13:34:36 UTC, Andrea Fontana wrote: On Friday, 31 August 2018 at 09:59:20 UTC, Dukc wrote: For me, it seems that for generality you should always add ref into foreach loop variable. The reason is this: One good reason:

Re: Is there any reason to use non-ref foreach?

2018-09-03 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 31 August 2018 at 09:59:20 UTC, Dukc wrote: For me, it seems that for generality you should always add ref into foreach loop variable. The reason is this: One good reason: https://forum.dlang.org/thread/dlhrrgvzmhladnphi...@forum.dlang.org

Re: Is there any reason to use non-ref foreach?

2018-08-31 Thread Dukc via Digitalmars-d-learn
On Friday, 31 August 2018 at 12:52:17 UTC, bauss wrote: In reality you're micro-optimizing something that doesn't require it. I think you misunderstood. I wasn't trying to optimize, I was looking for a general way to iterate. I can't see the benefit other than added complexity. I just

Re: Is there any reason to use non-ref foreach?

2018-08-31 Thread James Blachly via Digitalmars-d-learn
On Friday, 31 August 2018 at 12:52:17 UTC, bauss wrote: So basically ... Instead of copying the value, you're just copying the address. I can't see the benefit other than added complexity. I assume a benefit could be observed if you are copying a large struct instead of an int.

Re: Is there any reason to use non-ref foreach?

2018-08-31 Thread bauss via Digitalmars-d-learn
On Friday, 31 August 2018 at 09:59:20 UTC, Dukc wrote: For me, it seems that for generality you should always add ref into foreach loop variable. The reason is this: import std.experimental.all; struct NoCopies { @disable this(this); int payload; } void main() { auto range = new

Is there any reason to use non-ref foreach?

2018-08-31 Thread Dukc via Digitalmars-d-learn
For me, it seems that for generality you should always add ref into foreach loop variable. The reason is this: import std.experimental.all; struct NoCopies { @disable this(this); int payload; } void main() { auto range = new NoCopies[20]; foreach(const ref el; range)