The context is: Writing a container, containing type T, and a char * p to a memory region. Let's suppose the pointer is already suitably aligned for type T - the alignment issue is not part of the question. How do I default construct an element on that memory region?
((*T)(p))->T();
works for classes, but not with some builtin types.
((*T)(p)) = 0; // or simply memset
for integral types, pointers. Do these two cover everything, unions and what not? Is there a best practice for this, or some standard library feature? std::allocator::construct can do it, that is what e.g. std::vector uses, but it is not a static method, so I would need an instance of it. Is there some freestanding or static function that can do it?
--EDIT--
Yes, the answer is obvious, and I was dumb today -- placement new BTW, Now I'm trying to destroy the element...