D 2015/2016 Vision?

Namespace via Digitalmars-d digitalmars-d at puremagic.com
Tue Oct 6 01:46:42 PDT 2015


It's a step simpler with the new inline feature (works sadly only 
with the -inline flag):

----
pragma(inline, true)
auto scoped(T, Args...)(auto ref Args args) if (is(T == class)) {
     void[__traits(classInstanceSize, T)] buf = void;
     buf[] = typeid(T).init[];

     T obj = cast(T) buf.ptr;
     obj.__ctor(args);

     return obj;
}

class A {
     string name;

     this(string name) {
        this.name = name;
        writeln("Creating A");
     }

     ~this() {
        writeln("Destroying A");
     }

     void hello() {
        writeln("Hello, ", this.name);
     }
}

void main() {
     A a1 = scoped!A("Foo");
     a1.hello();
}
----



More information about the Digitalmars-d mailing list