Namespaces
Variants
Views
Actions

std::is_pointer_interconvertible_base_of

From cppreference.com
< cpp‎ | types
 
 
Utilities library
General utilities
Date and time
Function objects
Formatting library (C++20)
(C++11)
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

Elementary string conversions
(C++17)
(C++17)
 
Type support
Basic types
Fundamental types
Fixed width integer types (C++11)
Numeric limits
C numeric limits interface
Runtime type information
Type traits
Type categories
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Type properties
(C++11)
(C++11)
(C++14)
(C++11)
(C++11)(until C++20)
(C++11)(deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
(C++17)
Constant evaluation context
Supported operations
Relationships and property queries
(C++11)
(C++11)
is_pointer_interconvertible_base_of
(C++20)
Type modifications
(C++11)(C++11)(C++11)
Type transformations
(C++11)
(C++11)
(C++17)
(C++11)(until C++20)(C++17)
 
Defined in header <type_traits>
template< class Base, class Derived >
struct is_pointer_interconvertible_base_of;
(since C++20)

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), provides the member constant value equal to true. Otherwise value is false.

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

The behavior of a program that adds specializations for is_pointer_interconvertible_base_of or is_pointer_interconvertible_base_of_v is undefined.

Contents

[edit] Helper variable template

template< class Base, class Derived >

inline constexpr bool is_pointer_interconvertible_base_of_v =

    is_pointer_interconvertible_base_of<Base, Derived>::value;
(since C++20)

Inherited from std::integral_constant

Member constants

value
[static]
true 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), false otherwise
(public static member constant)

Member functions

operator bool
converts the object to bool, returns value
(public member function)
operator()
(C++14)
returns value
(public member function)

Member types

Type Definition
value_type bool
type std::integral_constant<bool, value>

[edit] 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-qulification 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 an empty class type, then all base classes of T (if any) are pointer-interconvertible base class of T.

If T is an non-empty standard layout class type, then all non-empty base classes of T (if any) are pointer-interconvertible base class of T, some empty base classes (if any) might also be pointer-interconvertible base class in this case.

[edit] Example

#include <iostream>
#include <type_traits>
 
struct Foo {};
 
struct Bar {};
 
class Baz : Foo, public Bar {
    int x;
};
 
class NonStdLayout : public Baz {
    int y;
};
 
int main() 
{
    std::cout << std::boolalpha
        << std::is_pointer_interconvertible_base_of_v<Bar, Baz> << '\n'
        << std::is_pointer_interconvertible_base_of_v<Foo, Baz> << '\n';
        << std::is_pointer_interconvertible_base_of_v<Baz, NonStdLayout> << '\n'
        << std::is_pointer_interconvertible_base_of_v<NonStdLayout, NonStdLayout> << '\n';
}

Output:

true
true
false
true

[edit] See also

checks if a type is derived from the other type
(class template) [edit]
(C++11)
checks if a type is a class (but not union) type and has no non-static data members
(class template) [edit]
checks if a type is a standard-layout type
(class template) [edit]