Is there an accepted idiom for hosting a backup storage for an object in place, but not for initializing it? Here is my naive solution:
#include <utility>
template<typename T>
union Slot {
T inst;
Slot() {}
~Slot() {}
template<typename... Args>
T* init(Args&&... args) { return new(&inst) T(std::forward<Args>(args) ...); }
void release() { inst.~T(); }
};
My immediate use case is for an object pool, but it will also be more useful.
source
share