Namespaces
Variants

std::meta::has_virtual_destructor

From cppreference.com
< cpp | meta
 
 
 
Reflection library
 
Reflection types and queries
Type properties
Type property queries
 
Defined in header <meta>
consteval bool has_virtual_destructor( std::meta::info r );
(since C++26)

Returns true if r represents a type that has a virtual destructor. Otherwise returns false.

Parameters

r - a reflection value

Return value

true if r represents a type that has a virtual destructor; otherwise false.

Exceptions

Throws std::meta::exception if r does not represent a type or type alias.

Notes

If a class C has a public virtual destructor, it can be derived from, and the derived object can be safely deleted through a pointer to the base object (GotW #18). In this case, std::meta::is_polymorphic_type(^^C) is true.

Example

#include <meta>

struct S {};
static_assert(not has_virtual_destructor(^^S));

struct B
{
    virtual ~B() {}
};
static_assert(has_virtual_destructor(^^B));

struct D : B
{
    ~D() {}
};
static_assert(has_virtual_destructor(^^D));

int main()
{
    B* pd = new D;
    delete pd;
}

See also

checks if reflected type has a non-deleted destructor
(function) [edit]
checks if reflected type is a polymorphic class type
(function) [edit]
checks if a type has a virtual destructor
(class template) [edit]