request in args option for opApply
BCS
ao at pathlink.com
Sun Jan 28 14:51:24 PST 2007
Reply to Frits,
> BCS wrote:
>
>> The foreach body is turned into a delegate taking (inout int), but it
>> is not marked as inout! I have a case where I'm trying to use opApply
>> where it can't be inout. Is this a bug?
>
> According to the spec, the signature of opApply must be "int
> opApply(int delegate(inout Type [, ...]) dg);", so it's actually a bug
> in your code that the delegate's parameter it isn't marked inout.
>
Hm.. Is that new? I shure, it used to allow "in".
> (unless of course you prefer to consider it a 'bug' in the spec that
> it's not allowed to be marked 'in' :) )
>
Yeah, I guess I'll have to stick with that approach. What else am I to do
in a "must not modify data" loop? Copy everything? Or what about a case like
this:
class C
{
char[] str;
int opApply(int delegate(inout char[]) dg)
{
for(int i = 1; i<=str.length; i++)
for(int ret = dg(str[0..i])) // fails b/c slices aren't L-values
return ret;
}
}
Oh well, I guess I'll just have to find workarounds.
More information about the Digitalmars-d-bugs
mailing list