C'tors from templates

Robert Clipsham robert at octarineparrot.com
Sat Oct 31 14:04:25 PDT 2009


dsimcha wrote:
> Is there a way to run a class's c'tor on a block of memory from a template
> function?  For example:
> 
> C newClass(C, CtorArgs...)(CtorArgs args) {
>     // Allocate, initialize.
>     // Want to call the c'tor that takes type CtorArgs.
> }

After reading the ticket you made, I was wondering if what you were 
looking for was:

http://www.digitalmars.com/d/1.0/class.html#allocators
http://www.digitalmars.com/d/1.0/class.html#deallocators

This allows you to use a custom allocator/deallocator and not worry 
about calling the correct ctor/dtor. If you want to change it for all 
classes, have a look at the _d_allocclass (or _d_newclass depending on 
your compiler/runtime) function in the runtime. If you change this you 
will need to recompile the runtime and it won't work for anyone else 
unless they use your modified runtime.



More information about the Digitalmars-d mailing list