[Issue 251] New: foreach does not allow updating inside with block

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jul 13 16:38:23 PDT 2006


http://d.puremagic.com/issues/show_bug.cgi?id=251

           Summary: foreach does not allow updating inside with block
           Product: D
           Version: 0.162
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: ashleymedlock at yahoo.com


Array members cannot be updated inside a with block for either structs or
classes.
Sample code below:

import std.stdio;


struct Bar { float a= 1.0; }

struct Foo
{
  Bar[]   arr;
}


void main( char[][] args )
{
  Foo foo ;//= new Foo();
  foo.arr.length = 20;

  with(foo)
  {
    foreach( int n, Bar bar; arr ) bar.a = 100;
  }
  foreach( int n, Bar bar; foo.arr ) writefln("A=%s", bar.a );
}


-- 




More information about the Digitalmars-d-bugs mailing list