search of a workaround

bearophile bearophileHUGS at lycos.com
Sat Feb 9 04:59:35 PST 2013


> (I'll ask to remove one limitation):

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


>     typeof(scoped!Foo(1))[10] foos; // Not initialized.
>
>     foreach (i, ref f; foos)
>         // f = new Foo(i * 10);
>         // f = scoped!Foo(i * 10);
>         f.x = i * 10;

What's the right/good way to initialize a scoped class instance? 
Currently this doesn't work:


import std.typecons;

class Foo {
     int x;
     this(int x_) { initialize(x_); }
     void initialize(int x_) {
         this.x = x_;
     }
}

void main() {
     typeof(scoped!Foo(1))[10] foos;
     foreach (i, ref f; foos)
         f.initialize(i * 10);
}


Bye,
bearophile


More information about the Digitalmars-d-learn mailing list