D is dead

ag0aep6g anonymous at example.com
Thu Aug 23 23:14:42 UTC 2018


On 08/23/2018 10:11 PM, Walter Bright wrote:
> On 8/23/2018 5:55 AM, Steven Schveighoffer wrote:
[...]
>> I think he means, if the range ITSELF doesn't allow copying, it won't 
>> work with foreach (because foreach makes a copy), but it will work 
>> with opApply.
> 
>      foreach (ref v; collection)
> 
> does not make a copy.

It makes a copy of `collection`.

> It's up to the programmer whether copying is done 
> with it. After all, if one is passing a struct instance around by value 
> instead of by ref, there is no escaping copying it. This should not be 
> surprising.

It's not obvious that using `collection` in a `foreach` means passing it 
around by value.


More information about the Digitalmars-d mailing list