template class VDeleter { public: VDeleter() : VDeleter([](T, VkAllocationCallbacks*) {}) {} VDeleter(std::function deletef) { this->deleter = [=](T obj) { deletef(obj, nullptr); }; } VDeleter(const VDeleter& instance, std::function deletef) { this->deleter = [&instance, deletef](T obj) { deletef(instance, obj, nullptr); }; } VDeleter(const VDeleter& device, std::function deletef) { this->deleter = [&device, deletef](T obj) { deletef(device, obj, nullptr); }; } ~VDeleter() { cleanup(); } const T* operator &() const { return &object; } T* replace() { cleanup(); return &object; } operator T() const { return object; } void operator=(T rhs) { if (rhs != object) { cleanup(); object = rhs; } } template bool operator==(V rhs) { return object == T(rhs); } private: T object{VK_NULL_HANDLE}; std::function deleter; void cleanup() { if (object != VK_NULL_HANDLE) { deleter(object); } object = VK_NULL_HANDLE; } };