fork download
  1. import std.stdio;
  2. class Foo {
  3. int a;
  4. int opApply(scope int delegate(ref int) dg)const
  5. {
  6. auto r = dg(a);
  7. if (r) return r;
  8. return 0;
  9. }
  10. }
  11. class Bar {
  12. Foo foo;
  13. this(){ foo = new Foo; }
  14. void hoge() const
  15. {
  16. writeln(foo.a);
  17. foreach(ref fuga; foo){
  18. fuga = 1;
  19. }
  20. writeln(foo.a);
  21. }
  22. }
  23. void main() {
  24. (new Bar()).hoge();
  25. }
Success #stdin #stdout 0.01s 2120KB
stdin
Standard input is empty
stdout
0
1