std::is_polymorphic

定义于头文件 <type_traits>
template< class T >
struct is_polymorphic;
(C++11 起)

T多态类(即声明或继承至少一个虚函数的非联合类),则提供等于 true 的成员常量 value 。对于任何其他类型, valuefalse

T 是非联合类类型,则 T 应为完整类型;否则行为未定义。

目录

模板参数

T - 要检查的类型

帮助变量模板

template< class T >
inline constexpr bool is_polymorphic_v = is_polymorphic<T>::value;
(C++17 起)

继承自 std::integral_constant

成员常量

value
[静态]
T多态类类型则为 true ,否则为 false
(公开静态成员常量)

成员函数

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

成员类型

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

示例

#include <iostream>
#include <type_traits>
 
struct A {
    int m;
};
 
struct B {
    virtual void foo();
};
 
struct C : B {};
 
int main()
{
    std::cout << std::boolalpha;
    std::cout << std::is_polymorphic<A>::value << '\n';
    std::cout << std::is_polymorphic<B>::value << '\n';
    std::cout << std::is_polymorphic<C>::value << '\n';
}

输出:

false
true
true

参阅

(C++11)
检查类型是否非联合类类型
(类模板)
(C++11)
检查类型是否为抽象类类型
(类模板)

版本历史

  • (当前 | 先前 2017年7月7日 (五) 21:31Fruderica讨论 | 贡献. . (1,415字节) (-347). . (撤销)
  • 当前 | 先前 2014年10月26日 (日) 18:15P12bot讨论 | 贡献 . . (1,762字节) (0). . (Fix some translations) (撤销)
  • 当前 | 先前 2013年7月2日 (二) 11:42P12bot讨论 | 贡献 . . (1,762字节) (-84). . (Use {{lc}}. Update links. Various fixes.) (撤销)
  • 当前 | 先前 2012年11月2日 (五) 16:06P12bot讨论 | 贡献 . . (1,846字节) (+257). . (r2.7.3) (机器人添加:de, en, es, fr, it, ja, pt, ru) (撤销)
  • 当前 | 先前 2012年10月27日 (六) 11:49P12讨论 | 贡献 . . (1,589字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 06:00TranslationBot讨论 | 贡献. . (1,589字节) (-26). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 03:33P12讨论 | 贡献 . . (1,615字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前) 2012年10月25日 (四) 12:00TranslationBot讨论 | 贡献. . (1,615字节) (+1,615). . (Translated from the English version using Google Translate)