[Issue 2442] New: opApply does not allow inferring parameter types when overloaded on const
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Nov 6 07:33:46 PST 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2442
Summary: opApply does not allow inferring parameter types when
overloaded on const
Product: D
Version: 2.019
Platform: PC
OS/Version: Linux
Status: NEW
Keywords: rejects-valid
Severity: critical
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: schveiguy at yahoo.com
If I have the following code:
struct S
{
int[] arr;
int opApply(int delegate(ref int v) dg)
{
int result = 0;
foreach(ref x; arr)
{
if(result = dg(x))
break;
}
return result;
}
int opApply(int delegate(ref const(int) v) dg) const
{
int result = 0;
foreach(ref x; arr)
{
if(result = dg(x))
break;
}
return result;
}
}
This is a properly const-decorated struct. I should be able to call
foreach(x; s)
Whether s is const or not. However, the compiler currently gives me an error:
void main()
{
S s;
foreach(x; s)
{
x = 5;
}
}
testit.d(32): Error: cannot uniquely infer foreach argument types
--
More information about the Digitalmars-d-bugs
mailing list