Spec-Zone.ru › C++

std::meta::has_virtual_destructor

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

is_destructible_typeis_trivially_destructible_typeis_nothrow_destructible_type
(C++26)(C++26)(C++26)
checks if reflected type has a non-deleted destructor
(function)
is_polymorphic_type
(C++26)
checks if reflected type is a polymorphic class type
(function)
has_virtual_destructor
(C++11)
checks if a type has a virtual destructor
(class template)

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/meta/has_virtual_destructor

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API