Namespaces
Variants

std::meta::is_pointer_interconvertible_base_of_type

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

Checks if reflected type Base (represented by base) is a pointer-interconvertible base of another type Derived (represented by derived).

If Derived is unambiguously derived from Base and every Derived object is pointer-interconvertible with its Base subobject, or if both are the same non-union class (in both cases ignoring cv-qualification), returns true. Otherwise returns false.

Equivalent to return std::is_pointer_interconvertible_base_of<Base, Derived>;.

If both Base and Derived are non-union class types, and they are not the same type (ignoring cv-qualification), Derived must be a complete type; otherwise the behavior is undefined.

Parameters

base, derived - reflection values to check

Return value

true if base represets a type that is pointer-interconvertible base of another type represented by derived, false otherwise.

Exceptions

Throws std::meta::exception if either base or derived does not represent a type or type alias.

Notes

std::is_pointer_interconvertible_base_of_v<T, U> may be true even if T is a private or protected base class of U.

Let

  • U be a complete object type,
  • T be a complete object type with cv-qualification not less than U,
  • u be any valid lvalue of U,

reinterpret_cast<T&>(u) always has well-defined result if std::is_pointer_interconvertible_base_of_v<T, U> is true.

If T and U are not the same type (ignoring cv-qualification) and T is a pointer-interconvertible base class of U, then both std::is_standard_layout_v<T> and std::is_standard_layout_v<U> are true.

If T is standard layout class type, then all base classes of T (if any) are pointer-interconvertible base class of T.

Example

#include <meta>

struct Foo {};

struct Bar {};

class Baz : Foo, public Bar { int x; };

class NonStdLayout : public Baz { int y; };

static_assert("all of:"
    and is_pointer_interconvertible_base_of_type(^^Bar, ^^Baz)
    and is_pointer_interconvertible_base_of_type(^^Foo, ^^Baz)
    and not is_pointer_interconvertible_base_of_type(^^Baz, ^^NonStdLayout)
    and is_pointer_interconvertible_base_of_type(^^NonStdLayout, ^^NonStdLayout)
);

int main() {}

See also

checks if reflected type is a pointer type
(function) [edit]
checks if two reflections represent types such that one type is a base of the other type
(function) [edit]
checks if two reflections represent types such that one type is a virtual base of the other type
(function) [edit]
checks if reflected type is a standard-layout type
(function) [edit]
checks if reflected type can be converted to the other type
(function) [edit]
checks if reflected type is a class (but not union) type and has no non-static data members
(function) [edit]
checks if a type is a pointer-interconvertible (initial) base of another type
(class template) [edit]