标准库标头 <type_traits> (C++11)

来自cppreference.com
< cpp‎ | header


 
 
标准库头
 

此标头是元编程库的一部分。

目录

辅助类
具有指定值的指定类型的编译期常量
(类模板)[编辑]
true_typestd::integral_constant<bool, true>
false_typestd::integral_constant<bool, false>
基础类型分类
(C++11)
检查类型是否为 void
(类模板)[编辑]
(C++11)(DR*)
检查类型是否为 std::nullptr_t
(类模板)[编辑]
检查类型是否为整数类型
(类模板)[编辑]
检查类型是否为浮点数类型
(类模板)[编辑]
(C++11)
检查类型是否为数组类型
(类模板)[编辑]
(C++11)
检查类型是否为枚举类型
(类模板)[编辑]
(C++11)
检查类型是否为联合体类型
(类模板)[编辑]
(C++11)
检查类型是否为非联合类类型
(类模板)[编辑]
检查类型是否为函数类型
(类模板)[编辑]
(C++11)
检查类型是否为指针类型
(类模板)[编辑]
检查类型是否为左值引用
(类模板)[编辑]
检查类型是否为右值引用
(类模板)[编辑]
检查类型是否为指向非静态成员对象的指针
(类模板)[编辑]
检查类型是否为指向非静态成员函数的指针
(类模板)[编辑]
复合类型分类
检查类型是否为基础类型
(类模板)[编辑]
检查类型是否为算术类型
(类模板)[编辑]
(C++11)
检查类型是否为标量类型
(类模板)[编辑]
(C++11)
检查类型是否为对象类型
(类模板)[编辑]
检查类型是否为复合类型
(类模板)[编辑]
检查类型是否为左值引用 或右值引用
(类模板)[编辑]
检查类型是否为指向非静态成员函数或对象的指针类型
(类模板)[编辑]
类型的性质
(C++11)
检查类型是否为 const 限定
(类模板)[编辑]
检查类型是否为 volatile 限定
(类模板)[编辑]
(C++11)(C++26 弃用)
检查类型是否平凡
(类模板)[编辑]
检查类型是否可平凡复制
(类模板)[编辑]
检查类型是否为标准布局类型
(类模板)[编辑]
(C++11)(C++20 弃用)
检查类型是否为简旧数据(POD)类型
(类模板)[编辑]
(C++11)(C++17 弃用)(C++20 移除)
检查类型是否为字面类型
(类模板)[编辑]
检查是否该类型对象的每一位都对其值有贡献
(类模板)[编辑]
(C++11)
检查类型是否为类(但非联合体)类型且无非静态数据成员
(类模板)[编辑]
检查类型是否为多态类类型
(类模板)[编辑]
检查类型是否为抽象类类型
(类模板)[编辑]
(C++14)
检查类型是否为 final 类类型
(类模板)[编辑]
检查类型是否为聚合类型
(类模板)[编辑]
检查类型是否为隐式生存期类型
(类模板)[编辑]
(C++11)
检查类型是否为有符号算术类型
(类模板)[编辑]
检查类型是否为无符号算术类型
(类模板)[编辑]
检查类型是否为有已知边界的数组类型
(类模板)[编辑]
检查类型是否为有未知边界的数组类型
(类模板)[编辑]
检查类型是否为有作用域枚举类型
(类模板)[编辑]
受支持操作
检查类型是否带有针对特定实参的构造函数
(类模板)[编辑]
检查类型是否有默认构造函数
(类模板)[编辑]
检查类型是否有复制构造函数
(类模板)[编辑]
检查类型是否能从右值引用构造
(类模板)[编辑]
检查类型是否有针对特定实参的赋值运算符
(类模板)[编辑]
检查类型是否有复制赋值运算符
(类模板)[编辑]
检查类型是否有移动赋值运算符
(类模板)[编辑]
检查类型是否有未被弃置的析构函数
(类模板)[编辑]
检查类型是否有虚析构函数
(类模板)[编辑]
检查类型的对象是否能与同类型或不同类型的对象交换
(类模板)[编辑]
检查在复制初始化中引用是否绑定到临时对象
(类模板)[编辑]
检查在直接初始化中引用是否绑定到临时对象
(类模板)[编辑]
性质查询
获取类型的对齐要求
(类模板)[编辑]
(C++11)
获取数组类型的维数
(类模板)[编辑]
(C++11)
获取数组类型在指定维数的大小
(类模板)[编辑]
类型关系
(C++11)
检查两个类型是否相同
(类模板)[编辑]
(C++11)
检查一个类型是否为另一个类型的基类
(类模板)[编辑]
检查一个类型是否为另一个类型的虚基类
(类模板)[编辑]
检查是否能转换一个类型为另一类型
(类模板)[编辑]
检查两个类型是否布局兼容
(类模板)[编辑]
检查一个类型是否为另一类型的指针可以互相转换(起始)基类
(类模板)[编辑]
检查类型能否以给定的实参类型调用(如同以 std::invoke
(类模板)[编辑]
常-易变性说明符
从给定类型移除 const 和/或 volatile 限定符
(类模板)[编辑]
(C++11)(C++11)(C++11)
向给定类型添加 const 和/或 volatile 限定符
(类模板)[编辑]
引用
从给定类型移除引用
(类模板)[编辑]
向给定类型添加左值 或右值 引用
(类模板)[编辑]
指针
从给定类型移除一层指针
(类模板)[编辑]
向给定类型添加一层指针
(类模板)[编辑]
符号修饰符
获取整数类型的对应有符号类型
(类模板)[编辑]
获取整数类型的对应无符号类型
(类模板)[编辑]
数组
从给定数组类型移除一个维度
(类模板)[编辑]
从给定数组类型移除所有维度
(类模板)[编辑]
杂项变换
(C++11 起)(C++23 弃用)
定义适于用作给定大小的类型的未初始化存储的类型
(类模板)[编辑]
(C++11 起)(C++23 弃用)
定义适于用作所有给定类型的未初始化存储的类型
(类模板)[编辑]
(C++11)
应用当按值传递实参给函数时所进行的类型变换
(类模板)[编辑]
std::remove_cvstd::remove_reference 结合
(类模板)[编辑]
(C++11)
条件性地从重载决议移除函数重载或模板特化
(类模板)[编辑]
基于编译时布尔值选择一个类型或另一个
(类模板)[编辑]
确定一组类型的公共类型
(类模板)[编辑]
确定一组类型的公共引用类型
(类模板)[编辑]
获得给定枚举类型的底层整数类型
(类模板)[编辑]
(C++11)(C++20 移除)(C++17)
推导以一组实参调用一个可调用对象的结果类型
(类模板)[编辑]
(C++17)
void 变参别名模板
(别名模板)[编辑]
返回不更改的类型实参
(类模板)[编辑]
获得包装于 std::reference_wrapper 的引用类型
(类模板)[编辑]
类型特征的运算
变参的逻辑与元函数
(类模板)[编辑]
变参的逻辑或元函数
(类模板)[编辑]
(C++17)
逻辑非元函数
(类模板)[编辑]

函数

成员关系
检查一个类型的对象是否与该类型的指定子对象指针可以互相转换
(函数模板)[编辑]
检查两个指定成员是否在两个指定类型中的公共起始序列中彼此对应
(函数模板)[编辑]
常量求值语境
检测调用是否在常量求值的语境内发生
(函数)[编辑]
在编译时检查指定对象是否在它的生存期内
(函数)[编辑]

[编辑]概要

namespace std {// 辅助类:template<class T, T v>struct integral_constant;   template<bool B>using bool_constant = integral_constant<bool, B>;using true_type = bool_constant<true>;using false_type = bool_constant<false>;   // 基础类型分类:template<class T>struct is_void;template<class T>struct is_null_pointer;template<class T>struct is_integral;template<class T>struct is_floating_point;template<class T>struct is_array;template<class T>struct is_pointer;template<class T>struct is_lvalue_reference;template<class T>struct is_rvalue_reference;template<class T>struct is_member_object_pointer;template<class T>struct is_member_function_pointer;template<class T>struct is_enum;template<class T>struct is_union;template<class T>struct is_class;template<class T>struct is_function;   // 复合类型分类:template<class T>struct is_reference;template<class T>struct is_arithmetic;template<class T>struct is_fundamental;template<class T>struct is_object;template<class T>struct is_scalar;template<class T>struct is_compound;template<class T>struct is_member_pointer;   // 类型的性质:template<class T>struct is_const;template<class T>struct is_volatile;template<class T>struct is_trivial;template<class T>struct is_trivially_copyable;template<class T>struct is_standard_layout;template<class T>struct is_empty;template<class T>struct is_polymorphic;template<class T>struct is_abstract;template<class T>struct is_final;template<class T>struct is_aggregate;   template<class T>struct is_signed;template<class T>struct is_unsigned;template<class T>struct is_bounded_array;template<class T>struct is_unbounded_array;template<class T>struct is_scoped_enum;   template<class T, class... Args>struct is_constructible;template<class T>struct is_default_constructible;template<class T>struct is_copy_constructible;template<class T>struct is_move_constructible;   template<class T, class U>struct is_assignable;template<class T>struct is_copy_assignable;template<class T>struct is_move_assignable;   template<class T, class U>struct is_swappable_with;template<class T>struct is_swappable;   template<class T>struct is_destructible;   template<class T, class... Args>struct is_trivially_constructible;template<class T>struct is_trivially_default_constructible;template<class T>struct is_trivially_copy_constructible;template<class T>struct is_trivially_move_constructible;   template<class T, class U>struct is_trivially_assignable;template<class T>struct is_trivially_copy_assignable;template<class T>struct is_trivially_move_assignable;template<class T>struct is_trivially_destructible;   template<class T, class... Args>struct is_nothrow_constructible;template<class T>struct is_nothrow_default_constructible;template<class T>struct is_nothrow_copy_constructible;template<class T>struct is_nothrow_move_constructible;   template<class T, class U>struct is_nothrow_assignable;template<class T>struct is_nothrow_copy_assignable;template<class T>struct is_nothrow_move_assignable;   template<class T, class U>struct is_nothrow_swappable_with;template<class T>struct is_nothrow_swappable;   template<class T>struct is_nothrow_destructible;   template<class T>struct has_virtual_destructor;   template<class T>struct has_unique_object_representations;   template<class T, class U>struct reference_constructs_from_temporary;template<class T, class U>struct reference_converts_from_temporary;   // 类型性质查询:template<class T>struct alignment_of;template<class T>struct rank;template<class T, unsigned I =0>struct extent;   // 类型关系:template<class T, class U>struct is_same;template<class Base, class Derived>struct is_base_of;template<class Base, class Derived>struct is_virtual_base_of;template<class From, class To>struct is_convertible;template<class From, class To>struct is_nothrow_convertible;template<class T, class U>struct is_layout_compatible;template<class Base, class Derived>struct is_pointer_interconvertible_base_of;   template<class Fn, class... ArgTypes>struct is_invocable;template<class R, class Fn, class... ArgTypes>struct is_invocable_r;   template<class Fn, class... ArgTypes>struct is_nothrow_invocable;template<class R, class Fn, class... ArgTypes>struct is_nothrow_invocable_r;   // const-volatile 修改:template<class T>struct remove_const;template<class T>struct remove_volatile;template<class T>struct remove_cv;template<class T>struct add_const;template<class T>struct add_volatile;template<class T>struct add_cv;   template<class T>using remove_const_t =typename remove_const<T>::type;template<class T>using remove_volatile_t =typename remove_volatile<T>::type;template<class T>using remove_cv_t =typename remove_cv<T>::type;template<class T>using add_const_t =typename add_const<T>::type;template<class T>using add_volatile_t =typename add_volatile<T>::type;template<class T>using add_cv_t =typename add_cv<T>::type;   // 引用修改:template<class T>struct remove_reference;template<class T>struct add_lvalue_reference;template<class T>struct add_rvalue_reference;   template<class T>using remove_reference_t =typename remove_reference<T>::type;template<class T>using add_lvalue_reference_t =typename add_lvalue_reference<T>::type;template<class T>using add_rvalue_reference_t =typename add_rvalue_reference<T>::type;   // 正负号修改:template<class T>struct make_signed;template<class T>struct make_unsigned;   template<class T>using make_signed_t =typename make_signed<T>::type;template<class T>using make_unsigned_t =typename make_unsigned<T>::type;   // 数组修改:template<class T>struct remove_extent;template<class T>struct remove_all_extents;   template<class T>using remove_extent_t =typename remove_extent<T>::type;template<class T>using remove_all_extents_t =typename remove_all_extents<T>::type;   // 指针修改:template<class T>struct remove_pointer;template<class T>struct add_pointer;   template<class T>using remove_pointer_t =typename remove_pointer<T>::type;template<class T>using add_pointer_t =typename add_pointer<T>::type;   // 其他变换:template<class T>struct type_identity;template<class T>struct remove_cvref;template<class T>struct decay;template<bool, class T =void>struct enable_if;template<bool, class T, class F>struct conditional;template<class... T>struct common_type;template<class T, class U, template<class>class TQual, template<class>class UQual>struct basic_common_reference {};template<class... T>struct common_reference;template<class T>struct underlying_type;template<class Fn, class... ArgTypes>struct invoke_result;template<class T>struct unwrap_reference;template<class T>struct unwrap_ref_decay;   template<class T>using type_identity_t =typename type_identity<T>::type;template<class T>using remove_cvref_t =typename remove_cvref<T>::type;template<class T>using decay_t =typename decay<T>::type;template<bool b, class T =void>using enable_if_t =typename enable_if<b, T>::type;template<bool b, class T, class F>using conditional_t =typename conditional<b, T, F>::type;template<class... T>using common_type_t =typename common_type<T...>::type;template<class... T>using common_reference_t =typename common_reference<T...>::type;template<class T>using underlying_type_t =typename underlying_type<T>::type;template<class Fn, class... ArgTypes>using invoke_result_t =typename invoke_result<Fn, ArgTypes...>::type;template<class T>using unwrap_reference_t =typename unwrap_reference<T>::type;template<class T>using unwrap_ref_decay_t =typename unwrap_ref_decay<T>::type;template<class...>using void_t =void;   // 逻辑运算符特征:template<class... B>struct conjunction;template<class... B>struct disjunction;template<class B>struct negation;   // 基础类型分类template<class T>inlineconstexprbool is_void_v = is_void<T>::value;template<class T>inlineconstexprbool is_null_pointer_v = is_null_pointer<T>::value;template<class T>inlineconstexprbool is_integral_v = is_integral<T>::value;template<class T>inlineconstexprbool is_floating_point_v = is_floating_point<T>::value;template<class T>inlineconstexprbool is_array_v = is_array<T>::value;template<class T>inlineconstexprbool is_pointer_v = is_pointer<T>::value;template<class T>inlineconstexprbool is_lvalue_reference_v = is_lvalue_reference<T>::value;template<class T>inlineconstexprbool is_rvalue_reference_v = is_rvalue_reference<T>::value;template<class T>inlineconstexprbool is_member_object_pointer_v = is_member_object_pointer<T>::value;template<class T>inlineconstexprbool is_member_function_pointer_v = is_member_function_pointer<T>::value;template<class T>inlineconstexprbool is_enum_v = is_enum<T>::value;template<class T>inlineconstexprbool is_union_v = is_union<T>::value;template<class T>inlineconstexprbool is_class_v = is_class<T>::value;template<class T>inlineconstexprbool is_function_v = is_function<T>::value;   // 复合类型分类template<class T>inlineconstexprbool is_reference_v = is_reference<T>::value;template<class T>inlineconstexprbool is_arithmetic_v = is_arithmetic<T>::value;template<class T>inlineconstexprbool is_fundamental_v = is_fundamental<T>::value;template<class T>inlineconstexprbool is_object_v = is_object<T>::value;template<class T>inlineconstexprbool is_scalar_v = is_scalar<T>::value;template<class T>inlineconstexprbool is_compound_v = is_compound<T>::value;template<class T>inlineconstexprbool is_member_pointer_v = is_member_pointer<T>::value;   // 类型的性质template<class T>inlineconstexprbool is_const_v = is_const<T>::value;template<class T>inlineconstexprbool is_volatile_v = is_volatile<T>::value;template<class T>inlineconstexprbool is_trivial_v = is_trivial<T>::value;template<class T>inlineconstexprbool is_trivially_copyable_v = is_trivially_copyable<T>::value;template<class T>inlineconstexprbool is_standard_layout_v = is_standard_layout<T>::value;template<class T>inlineconstexprbool is_empty_v = is_empty<T>::value;template<class T>inlineconstexprbool is_polymorphic_v = is_polymorphic<T>::value;template<class T>inlineconstexprbool is_abstract_v = is_abstract<T>::value;template<class T>inlineconstexprbool is_final_v = is_final<T>::value;template<class T>inlineconstexprbool is_aggregate_v = is_aggregate<T>::value;template<class T>inlineconstexprbool is_signed_v = is_signed<T>::value;template<class T>inlineconstexprbool is_unsigned_v = is_unsigned<T>::value;template<class T>inlineconstexprbool is_bounded_array_v = is_bounded_array<T>::value;template<class T>inlineconstexprbool is_unbounded_array_v = is_unbounded_array<T>::value;template<class T>inlineconstexprbool is_scoped_enum_v = is_scoped_enum<T>::value;template<class T, class... Args>inlineconstexprbool is_constructible_v = is_constructible<T, Args...>::value;template<class T>inlineconstexprbool is_default_constructible_v = is_default_constructible<T>::value;template<class T>inlineconstexprbool is_copy_constructible_v = is_copy_constructible<T>::value;template<class T>inlineconstexprbool is_move_constructible_v = is_move_constructible<T>::value;template<class T, class U>inlineconstexprbool is_assignable_v = is_assignable<T, U>::value;template<class T>inlineconstexprbool is_copy_assignable_v = is_copy_assignable<T>::value;template<class T>inlineconstexprbool is_move_assignable_v = is_move_assignable<T>::value;template<class T, class U>inlineconstexprbool is_swappable_with_v = is_swappable_with<T, U>::value;template<class T>inlineconstexprbool is_swappable_v = is_swappable<T>::value;template<class T>inlineconstexprbool is_destructible_v = is_destructible<T>::value;template<class T, class... Args>inlineconstexprbool is_trivially_constructible_v = is_trivially_constructible<T, Args...>::value;template<class T>inlineconstexprbool is_trivially_default_constructible_v = is_trivially_default_constructible<T>::value;template<class T>inlineconstexprbool is_trivially_copy_constructible_v = is_trivially_copy_constructible<T>::value;template<class T>inlineconstexprbool is_trivially_move_constructible_v = is_trivially_move_constructible<T>::value;template<class T, class U>inlineconstexprbool is_trivially_assignable_v = is_trivially_assignable<T, U>::value;template<class T>inlineconstexprbool is_trivially_copy_assignable_v = is_trivially_copy_assignable<T>::value;template<class T>inlineconstexprbool is_trivially_move_assignable_v = is_trivially_move_assignable<T>::value;template<class T>inlineconstexprbool is_trivially_destructible_v = is_trivially_destructible<T>::value;template<class T, class... Args>inlineconstexprbool is_nothrow_constructible_v = is_nothrow_constructible<T, Args...>::value;template<class T>inlineconstexprbool is_nothrow_default_constructible_v = is_nothrow_default_constructible<T>::value;template<class T>inlineconstexprbool is_nothrow_copy_constructible_v = is_nothrow_copy_constructible<T>::value;template<class T>inlineconstexprbool is_nothrow_move_constructible_v = is_nothrow_move_constructible<T>::value;template<class T, class U>inlineconstexprbool is_nothrow_assignable_v = is_nothrow_assignable<T, U>::value;template<class T>inlineconstexprbool is_nothrow_copy_assignable_v = is_nothrow_copy_assignable<T>::value;template<class T>inlineconstexprbool is_nothrow_move_assignable_v = is_nothrow_move_assignable<T>::value;template<class T, class U>inlineconstexprbool is_nothrow_swappable_with_v = is_nothrow_swappable_with<T, U>::value;template<class T>inlineconstexprbool is_nothrow_swappable_v = is_nothrow_swappable<T>::value;template<class T>inlineconstexprbool is_nothrow_destructible_v = is_nothrow_destructible<T>::value;template<class T>inlineconstexprbool has_virtual_destructor_v = has_virtual_destructor<T>::value;template<class T>inlineconstexprbool has_unique_object_representations_v = has_unique_object_representations<T>::value;template<class T, class U>inlineconstexprbool reference_constructs_from_temporary_v = reference_constructs_from_temporary<T, U>::value;template<class T, class U>inlineconstexprbool reference_converts_from_temporary_v = reference_converts_from_temporary<T, U>::value;   // 类型性质查询template<class T>inlineconstexpr size_t alignment_of_v = alignment_of<T>::value;template<class T>inlineconstexpr size_t rank_v = rank<T>::value;template<class T, unsigned I =0>inlineconstexpr size_t extent_v = extent<T, I>::value;   // 类型关系template<class T, class U>inlineconstexprbool is_same_v = is_same<T, U>::value;template<class Base, class Derived>inlineconstexprbool is_base_of_v = is_base_of<Base, Derived>::value;template<class Base, class Derived>inlineconstexprbool is_virtual_base_of_v = is_virtual_base_of<Base, Derived>::value;template<class From, class To>inlineconstexprbool is_convertible_v = is_convertible<From, To>::value;template<class From, class To>inlineconstexprbool is_nothrow_convertible_v = is_nothrow_convertible<From, To>::value;template<class T, class U>inlineconstexprbool is_layout_compatible_v = is_layout_compatible<T, U>::value;template<class Base, class Derived>inlineconstexprbool is_pointer_interconvertible_base_of_v = is_pointer_interconvertible_base_of<Base, Derived>::value;template<class Fn, class... ArgTypes>inlineconstexprbool is_invocable_v = is_invocable<Fn, ArgTypes...>::value;template<class R, class Fn, class... ArgTypes>inlineconstexprbool is_invocable_r_v = is_invocable_r<R, Fn, ArgTypes...>::value;template<class Fn, class... ArgTypes>inlineconstexprbool is_nothrow_invocable_v = is_nothrow_invocable<Fn, ArgTypes...>::value;template<class R, class Fn, class... ArgTypes>inlineconstexprbool is_nothrow_invocable_r_v = is_nothrow_invocable_r<R, Fn, ArgTypes...>::value;   // 逻辑运算符特征:template<class... B>inlineconstexprbool conjunction_v = conjunction<B...>::value;template<class... B>inlineconstexprbool disjunction_v = disjunction<B...>::value;template<class B>inlineconstexprbool negation_v = negation<B>::value;   // 成员关系template<class S, class M>constexprbool is_pointer_interconvertible_with_class(M S::*m)noexcept;template<class S1, class S2, class M1, class M2>constexprbool is_corresponding_member(M1 S1::*m1, M2 S2::*m2)noexcept;   // 常量求值语境constexprbool is_constant_evaluated()noexcept; consteval bool is_within_lifetime(constauto*)noexcept;}

[编辑]类模板 std::integral_constant

namespace std {template<class T, T v>struct integral_constant {staticconstexpr T value = v;using value_type = T;using type = integral_constant<T, v>;constexpr operator value_type()constnoexcept{return value;}constexpr value_type operator()()constnoexcept{return value;}};}
close