std::meta::has_virtual_destructor
From cppreference.com
| 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
Run this code
#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
(C++26)(C++26)(C++26) |
checks if reflected type has a non-deleted destructor (function) |
(C++26) |
checks if reflected type is a polymorphic class type (function) |
(C++11) |
checks if a type has a virtual destructor (class template) |