std::is_final
来自 cppreference.cn
定义于头文件 <type_traits> |
||
template< class T > struct is_final; |
(自 C++14 起) | |
std::is_final
是一个 一元类型特征。
如果 T
是一个 final 类,则提供成员常量 value
等于 true。对于任何其他类型,value
为 false。
如果 T
是一个不完整的类类型,则行为未定义。
如果程序为 std::is_final
或 std::is_final_v
(自 C++17 起) 添加特化,则行为未定义。
目录 |
[编辑] 模板参数
T | - | 要检查的类型 |
[编辑] 辅助变量模板
template< class T > constexpr bool is_final_v = is_final<T>::value; |
(自 C++17 起) | |
继承自 std::integral_constant
成员常量
value [静态] |
true 如果 T 是 final 类类型,否则为 false(公有静态成员常量) |
成员函数
operator bool |
将对象转换为 bool,返回 value (公有成员函数) |
operator() (C++14) |
返回 value (公有成员函数) |
成员类型
类型 | 定义 |
value_type
|
bool |
type
|
std::integral_constant<bool, value> |
[编辑] 注解
std::is_final
由 LWG issue 2112 的决议引入。
联合体 可以被声明为 final
(并且 std::is_final
将会检测到这一点),即使联合体在任何情况下都不能用作基类。
特性测试 宏 | 值 | Std | 特性 |
---|---|---|---|
__cpp_lib_is_final |
201402L |
(C++14) | std::is_final
|
[编辑] 示例
运行此代码
#include <type_traits> class A {}; static_assert(std::is_final_v<A> == false); class B final {}; static_assert(std::is_final_v<B> == true); union U final { int x; double d; }; static_assert(std::is_final_v<U> == true); int main() { }
[编辑] 参见
(C++11) |
检查类型是否为非联合类类型 (类模板) |
(C++11) |
检查类型是否为多态类类型 (类模板) |