Namespaces
Variants

std:: is_final

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
Type properties
(C++11)
(C++11)
is_final
(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 T >
struct is_final ;
(C++14 起)

std::is_final 是一个 UnaryTypeTrait

如果 T final 类,则提供成员常量 value 等于 true 。对于任何其他类型, value false

如果 T 是不完整类类型,则行为未定义。

如果程序为 std::is_final std::is_final_v (since C++17) 添加特化,则行为是未定义的。

目录

模板参数

T - 待检查的类型

辅助变量模板

template < class T >
constexpr bool is_final_v = is_final < T > :: value ;
(C++17 起)

继承自 std:: integral_constant

成员常量

value
[static]
T 为 final 类类型则为 true ,否则为 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 会检测到该特性),尽管联合体在任何情况下都不能作为基类使用。

特性测试宏 标准 功能特性
__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)
检查类型是否为非联合类类型
(类模板)
检查类型是否为多态类类型
(类模板)