anyway to pass the context of an inner type to a template so it can be constructed?

aliak something at something.com
Wed Jun 27 12:02:10 UTC 2018


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


More information about the Digitalmars-d-learn mailing list