import std.stdio; class Foo { int a; int opApply(scope int delegate(ref int) dg)const { auto r = dg(a); // なんで渡せるの? if (r) return r; return 0; } } class Bar { Foo foo; this(){ foo = new Foo; } void hoge() const { writeln(foo.a); // なんでforeachbodyがconstじゃないdelegateで渡せちゃうの? foreach(ref fuga; foo){ fuga = 1; } // なんで書き換えられちゃってるの? writeln(foo.a); } } void main() { (new Bar()).hoge(); }