Function dtor

Synopsis

#include <src/entt/meta/factory.hpp>

template <auto Func>
auto dtor() noexcept

Description

Assigns a meta destructor to a meta type.

Free functions can be assigned to meta types in the role of destructors. The signature of the function should identical to the following:

void(Type &);

The purpose is to give users the ability to free up resources that require special treatment before an object is actually destroyed.

Template Parameters

Func - The actual function to use as a destructor.

Returns
A meta factory for the parent type.

Source

Lines 544-558 in src/entt/meta/factory.hpp.

template<auto Func>
auto dtor() ENTT_NOEXCEPT {
    static_assert(std::is_invocable_v<decltype(Func), Type &>, "The function doesn't accept an object of the type provided");
    auto * const type = internal::meta_info<Type>::resolve();
    ENTT_ASSERT(!type->dtor);
    type->dtor = [](void *instance) {
        if(instance) {
            std::invoke(Func, *static_cast<Type *>(instance));
        }
    };
    return meta_factory<Type>{};
}





Add Discussion

Log in to comment