Spec-Zone.ru › C++

std::meta::is_polymorphic_type

Defined in header <meta>
consteval bool is_polymorphic_type( std::meta::info r );
(since C++26)

Returns true if r represents a polymorphic class (that is, a non-union class that declares or inherits at least one virtual function). Otherwise returns false.

Parameters

r - a reflection value

Return value

true if r represents a polymorphic class type; otherwise false.

Exceptions

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

Example

#include <meta>

struct A { int m; };
static_assert(!is_polymorphic_type(^^A));

struct B { virtual void foo(); };
static_assert(is_polymorphic_type(^^B));

struct C : B {};
static_assert(is_polymorphic_type(^^C));
 
struct D { virtual ~D() = default; };
static_assert(is_polymorphic_type(^^D));
 
// Virtual inheritance as such does not make a type polymorphic.
struct E : A {};
static_assert(!is_polymorphic_type(^^E));

struct F : virtual A {};
static_assert(!is_polymorphic_type(^^F));

struct AX : A {};
struct AY : A {};
struct XY : virtual AX, virtual AY {};
static_assert(!is_polymorphic_type(^^XY));

int main() {}

See also

is_polymorphic
(C++11)
checks if a type is a polymorphic class type
(class template)
is_class_type
(C++26)
checks if reflected type is a non-union class type
(function)
is_abstract_type
(C++26)
checks if reflected type is an abstract class type
(function)
has_virtual_destructor
(C++26)
checks if reflected type has a virtual destructor
(function)

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

Spec-Zone.ru

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