C'tors from templates

dsimcha dsimcha at yahoo.com
Sat Oct 31 14:29:09 PDT 2009


== Quote from Robert Clipsham (robert at octarineparrot.com)'s article
> 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.

Yes, but...

Unless I hack the compiler, only *runtime* type info gets passed to this function.
 I need *compile time* type info so it can be passed to templates to generate/get
the bit mask for the type for my precise heap scanning scheme.



More information about the Digitalmars-d mailing list