As noted in the comments, this is the Undefined Behavior / Compiler extension.
You can do what you want:
template<typename T>
std::function<void(T*)> defer_dtor()
{
return [](T* ptr) {ptr->~T();};
}
or directly (more like your question, but the unique lambda type cannot be added directly to the list.)
auto destructor = [&]{someObject->~SomeClass();};
destructor();
: delete ptr. , , , delete ptr, std::shared_ptr.
[]
: " ".
. , . ? , virtual. , ? , ->~Type() ?