diff --git a/src/lib/opaque-holder.hpp b/src/lib/opaque-holder.hpp index 799703ce7..41ebe662d 100644 --- a/src/lib/opaque-holder.hpp +++ b/src/lib/opaque-holder.hpp @@ -616,16 +616,30 @@ namespace lib { public: - InPlaceBuffer () - { - placeDefault(); - } - ~InPlaceBuffer () { destroy(); } + InPlaceBuffer () + { + placeDefault(); + } + + /** immediately emplace an embedded subclass type */ + template + InPlaceBuffer (TY*, ARGS&& ...args) + { + new(&buf_) TY (std::forward (args)...); + } + + /** helper to mark the subclass type to create. + * @remarks we can not specify explicit template arguments on ctor calls, + * so the only way is to use a dummy marker argument to pass the type. + * Use as `InPlaceBuffer(embedType, arg1, arg2, arg3)` */ + template + static auto embedType() { return (SUB*) nullptr; } + /** Abbreviation for placement new */ template