Namespaces
Variants

std:: is_pointer_interconvertible_base_of

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
Type properties
(C++11)
(C++11)
(C++14)
(C++11) (deprecated in C++26)
(C++11) ( until C++20* )
(C++11) (deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
(C++17)
Supported operations
Relationships and property queries
Type modifications
Type transformations
(C++11) (deprecated in C++23)
(C++11) (deprecated in C++23)
(C++11)
(C++11) ( until C++20* ) (C++17)

Compile-time rational arithmetic
Compile-time integer sequences
定义于头文件 <type_traits>
template < class Base, class Derived >
struct is_pointer_interconvertible_base_of ;
(C++20 起)

如果 Derived 明确继承自 Base 且每个 Derived 对象都与其 Base 子对象 指针可互转换 ,或者两者为同一非联合类(两种情况均忽略 cv 限定符),则提供等于 true 的成员常量 value 。否则 value false

如果 Base Derived 均为非联合类类型,且二者类型不同(忽略 cv 限定符),则 Derived 必须是 完整类型 ;否则行为未定义。

如果程序为 std::is_pointer_interconvertible_base_of std::is_pointer_interconvertible_base_of_v 添加特化,则行为未定义。

目录

辅助变量模板

template < class Base, class Derived >

inline constexpr bool is_pointer_interconvertible_base_of_v =

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

继承自 std:: integral_constant

成员常量

value
[static]
Derived 明确继承自 Base 且每个 Derived 对象与其 Base 子对象可 指针互转换 ,或两者为同一非联合类(两种情况均忽略 cv 限定符),则为 true ;否则为 false
(公开静态成员常量)

成员函数

operator bool
转换对象为 bool 类型,返回 value
(公开成员函数)
operator()
(C++14)
返回 value
(公开成员函数)

成员类型

类型 定义
value_type bool
type std:: integral_constant < bool , value >

注释

std :: is_pointer_interconvertible_base_of_v < T, U > 可能返回 true ,即使 T U 的私有或受保护基类。

  • U 为完整对象类型,
  • T 为 cv 限定不低于 U 的完整对象类型,
  • u U 类型的任意有效左值,

reinterpret_cast < T & > ( u ) std :: is_pointer_interconvertible_base_of_v < T, U > true 时始终具有明确定义的结果。

如果 T U 不是同一类型(忽略 cv 限定符)且 T U 的指针可互转换基类,则 std:: is_standard_layout_v < T > std:: is_standard_layout_v < U > 均为 true

如果 T 是标准布局类类型,那么 T 的所有基类(如果存在)都是 T 的指针可互转换基类。

功能测试 标准 功能特性
__cpp_lib_is_pointer_interconvertible 201907L (C++20) 指针可互转换特性:

示例

#include <type_traits>
struct Foo {};
struct Bar {};
class Baz : Foo, public Bar { int x; };
class NonStdLayout : public Baz { int y; };
static_assert(std::is_pointer_interconvertible_base_of_v<Bar, Baz>);
static_assert(std::is_pointer_interconvertible_base_of_v<Foo, Baz>);
static_assert(not std::is_pointer_interconvertible_base_of_v<Baz, NonStdLayout>);
static_assert(std::is_pointer_interconvertible_base_of_v<NonStdLayout, NonStdLayout>);
int main() {}

参见

(C++11)
检查一个类型是否是另一个类型的基类
(类模板)
(C++11)
检查一个类型是否为类(非联合)类型且无非静态数据成员
(类模板)
检查一个类型是否为 标准布局 类型
(类模板)