[Issue 16131] A struct is being copied unnecessarily when initialized

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Jun 8 08:52:34 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=16131

--- Comment #6 from Sobirari Muhomori <dfj1esp02 at sneakemail.com> ---
Try this:

struct Foo {
    int x;
    Fiber fib;
    @disable this(this);
    void create(int x) {
        this.x = x;
        fib = new Fiber(&run);
    }
    void run() {
        writeln("Hello from: ", x);
    }
}

void main() {
    Foo[10] foos; // OR with:  = void;
    foreach(int i, ref foo; foos) {
        foo.create(i);
    }
    foreach(ref foo; foos) {
        foo.fib.call();
    }
}

--


More information about the Digitalmars-d-bugs mailing list