Forget the "why" for the moment.

T construct(T, ARGS...)(ARGS args) if( is(T==class) ) {
   auto buffer = new ubyte[__traits(classInstanceSize, T)];
   T cls = cast(T)buffer.ptr;

   // Is this really the best way to do this?
   buffer[] = cast(ubyte[])typeid(T).initializer()[];
   cls.__ctor(args);

   return cls;
}

My question is this: Is this the correct way to do it? There are steps here that seem kinda arbitrary, to say the least.

I am looking for something akin to C++'s placement new.

Thank you,
Shachar

Reply via email to