std::is_final
在标头
<type_traits> 定义 |
||
template< class T >
struct is_final; |
(C++14 起) | |
std::is_final
是一元类型特征 (UnaryTypeTrait) 。
如果 T
是最终类,那么提供的成员常量 value
等于 true。对于其它任何类型,value
等于 false。
如果 T
是不完整的类类型,那么行为未定义。
如果程序添加了 std::is_final
或 std::is_final_v
(C++17 起) 的特化,那么行为未定义。
模板形参
T | - | 要检查的类型 |
辅助变量模板
template< class T >
inline constexpr bool is_final_v = is_final<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> |
注解
std::is_final
由 LWG 问题 2112 的解决方案引入。
联合体可以被声明为 final
(而 std::is_final
将检测到它),尽管联合体在任何情况下都不能作为基类。
功能特性测试宏 | 值 | 标准 | 功能特性 |
---|---|---|---|
__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)
|
检查类型是否为多态类类型 (类模板) |