[Issue 16255] New: std.algorithm.iteration.each on opApply doesn't support ref
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Fri Jul 8 18:04:49 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=16255
Issue ID: 16255
Summary: std.algorithm.iteration.each on opApply doesn't
support ref
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: schveiguy at yahoo.com
Look at this code:
struct S
{
int x;
int opApply(int delegate(ref int _x) dg) { return dg(x); }
}
void main()
{
S s;
foreach(ref a; s) ++a;
assert(s.x == 1);
}
If we replace the foreach loop with an each call, we would do:
s.each!"++a";
Except it doesn't work. When each accepts the iterable, it accepts it by value.
It should accept it by reference (if it's a class, it could take the class
reference by value). Otherwise, the point of using ref throughout each is kind
of useless.
--
More information about the Digitalmars-d-bugs
mailing list