
Hi Fernando,
It clearly could, though it worries me than in that case it wouldn't be an "in-place" factory but just a ordinary factory. While I can understand your need from your side, specially assuming that the pointer is an implementation detail, it feels a bit of a hack from the in-place factory POV.
Ok, but I think having it could improve in_place factory usability in several places. I'm not the only one working on a library proposal with small object optimization currently. Maybe also Steven's TypeErasure library could benefit from this.
<snip> IIRC typical implementations of new call malloc() then in place new, so, couldn't you do the same?
I can call either malloc or global new (both will give correctly aligned memory), but this will defeat class specific memory management. If operator new and delete are redefined for a given class, I'd like to (and the library user also would me to) use the redefined one. Moreover, if new/delete are redefined, the memory allocated by: void *b=::operator new (sizeof T); // memory allocated through global operator new p= new (b) T(args); // this is what in_place does cannot be deallocated by delete p; I think something like the following should work, but it seems clumsy and I still have to check: template<typename T> struct new_invoker : T { static void * alloc() { return operator new(sizeof T); } // should look up operator new in T scope before global scope static void dealloc(void *p) { return operator delete(p); } // should look up operator delete in T scope before global scope private: new_invoker(); new_invoker(new_invoker const &); void ~new_invoker(); }; // specializations for non-class types omitted Corrado -- __________________________________________________________________________ dott. Corrado Zoccolo mailto:zoccolo@di.unipi.it PhD - Department of Computer Science - University of Pisa, Italy -------------------------------------------------------------------------- The self-confidence of a warrior is not the self-confidence of the average man. The average man seeks certainty in the eyes of the onlooker and calls that self-confidence. The warrior seeks impeccability in his own eyes and calls that humbleness. Tales of Power - C. Castaneda