Ie:

struct S {
    @disable this();
    this(int i) {}
}

struct Container(T) {
    T value;
    this(auto ref T value) {
        this.value = value;
    }
}

void main() {
    auto a = Container!S(S(3)); // can't do this.
}

I can build a custom constructor for Container that makes this work:

static auto construct(Args...)(auto ref Args args) {
    import std.algorithm: move;
    auto value = T(args);
    auto opt = Container!T.init;
    opt.value = move(value);
    return move(opt);
}

But is there a way to do it without adding a custom constructor type?

Cheers,
- Ali

Reply via email to