[Issue 251] foreach does not allow updating inside with block
BCS
BCS at pathlink.com
Thu Jul 13 17:11:58 PDT 2006
David Medlock wrote:
> d-bugmail at puremagic.com wrote:
>
>> http://d.puremagic.com/issues/show_bug.cgi?id=251
>>
>>
>>
>>
>>
>> ------- Comment #1 from shro8822 at uidaho.edu 2006-07-13 18:46 -------
>> use inout
>>
>> with(foo)
>> {
>> foreach( int n, inout Bar bar; arr ) bar.a = 100;
>> }
>>
>> haven't tested this but...
>>
>> INVALID I think
>>
>>
> Has this changed?
>
> I know the opApply used to require inout arguments, and they were
> implied mutable on iteration.
I think that a basic foreach on an array requiters inout to change things.
http://www.digitalmars.com/d/statement.html#foreach
The opApply does requirer the inout (I ran into this a week or so back).
This seems like a problem to me. A non-inout version should be allowed
so that read only access can be granted.
More information about the Digitalmars-d-bugs
mailing list