[Issue 7543] New: inout opApply should work properly
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Feb 19 03:50:15 PST 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7543
Summary: inout opApply should work properly
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: k.hara.pg at gmail.com
Depends on: 7542
--- Comment #0 from Kenji Hara <k.hara.pg at gmail.com> 2012-02-19 03:50:14 PST ---
After fixing issue 7542, inout opApply should work on foreach.
class C
{
int[] arr;
this(int[] a){ arr = a; }
int opApply(int delegate(ref inout(int)) dg) inout
{
foreach (ref e; arr)
if (auto r = dg(e)) return r;
return 0;
}
}
void main()
{
size_t i;
i = 0;
foreach (e; new C([1,2,3]))
{
static assert(is(typeof(e) == int));
assert(e == ++i);
e = 10;
}
assert(i == 3);
i = 0;
foreach (e; new const(C)([1,2,3]))
{
static assert(is(typeof(e) == const int));
assert(e == ++i);
static assert(!__traits(compiles, e = 10));
}
assert(i == 3);
i = 0;
foreach (e; new immutable(C)([1,2,3]))
{
static assert(is(typeof(e) == immutable int));
assert(e == ++i);
static assert(!__traits(compiles, e = 10));
}
assert(i == 3);
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list