This currently fails unless you mark the class as static:

auto construct(T)() {
    return new T;
}
void main() {
    class C {}
    auto s = construct!C;
}

So wondering if there's anything that can be done to get the above working?


Or if there isn't then how could the compiler be enhanced to allow for something like this if possible?

===
The use case is for a non-nullable type, where I want to guarantee that the value inside will never be null. I can't do it for inner classes though. And I can't allow the user to do something like:

void main() {
    class C {}
    auto s = construct(new C);
}

Because I can't guarantee that's not null.


Cheers,
- Ali

Reply via email to