foreach, RefCounted and non-copyable range
Fynn Schröder
fynnos at live.com
Sun Jan 17 12:15:00 UTC 2021
I'm puzzled why RefCounted and foreach do not work well together,
i.e.:
```
auto range = refCounted(nonCopyableRange); // ok
foreach(e; range) // Error: struct is not copyable because it is
annotated with @disable
// do something
```
See https://run.dlang.io/is/u271nK for a full example where I
also compared the foreach compiler rewrite and the manual rewrite
of foreach to a simple for loop.
Somehow foreach makes a copy of the internal payload of
RefCounted (run the example and look at the address of the
payload/range).
Is this a bug and is there any way around it?
More information about the Digitalmars-d-learn
mailing list