Namespaces
Variants

Standard library header <type_traits> (C++11)

From cppreference.net
Standard library headers

此头文件是 元编程 库的组成部分。

目录

辅助类
具有指定类型和指定值的编译期常量
(类模板)
true_type std:: integral_constant < bool , true >
false_type std:: integral_constant < bool , false >
基本类型分类
(C++11)
检查类型是否为 void
(类模板)
(C++11) ( DR* )
检查类型是否为 std::nullptr_t
(类模板)
检查类型是否为整型
(类模板)
检查类型是否为浮点类型
(类模板)
(C++11)
检查类型是否为数组类型
(类模板)
(C++11)
检查类型是否为枚举类型
(类模板)
(C++11)
检查类型是否为联合类型
(类模板)
(C++11)
检查类型是否为非联合类类型
(类模板)
检查类型是否为函数类型
(类模板)
(C++11)
检查类型是否为指针类型
(类模板)
检查类型是否为 lvalue reference
(类模板)
检查类型是否为 rvalue reference
(类模板)
检查类型是否为非静态成员对象指针
(类模板)
检查类型是否为非静态成员函数指针
(类模板)
复合类型分类
检查类型是否为基本类型
(类模板)
检查类型是否为算术类型
(类模板)
(C++11)
检查类型是否为标量类型
(类模板)
(C++11)
检查类型是否为对象类型
(类模板)
检查类型是否为复合类型
(类模板)
检查类型是否为 lvalue reference rvalue reference
(类模板)
检查类型是否为指向非静态成员函数或对象的指针
(类模板)
类型属性
(C++11)
检查类型是否具有 const 限定符
(类模板)
检查类型是否具有 volatile 限定符
(类模板)
(C++11) (C++26 中弃用)
检查类型是否为平凡类型
(类模板)
检查类型是否为可平凡复制的
(类模板)
检查类型是否为 标准布局 类型
(类模板)
(C++11) (deprecated in C++20)
检查类型是否为简旧数据类型
(类模板)
(C++11) (C++17 中弃用) (C++20 中移除)
检查类型是否为字面类型
(类模板)
检查类型对象表示中的每个位是否都对其值有贡献
(类模板)
(C++11)
检查类型是否为类(但不包括联合体)类型且无非静态数据成员
(类模板)
检查类型是否为多态类类型
(类模板)
检查类型是否为抽象类类型
(类模板)
(C++14)
检查类型是否为最终类类型
(类模板)
检查类型是否为聚合类型
(类模板)
检查类型是否为隐式生命周期类型
(类模板)
(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_cv std::remove_reference
(类模板)
(C++11)
有条件地 从重载决议中移除 函数重载或模板特化
(类模板)
根据编译期布尔值选择两种类型之一
(类模板)
确定一组类型的公共类型
(类模板)
确定一组类型的共同引用类型
(类模板)
获取给定枚举类型的底层整数类型
(类模板)
(C++11) (removed in C++20) (C++17)
推导可调用对象与一组参数调用的结果类型
(类模板)
(C++17)
void 可变参数别名模板
(别名模板)
返回未经修改的类型参数
(类模板)
获取封装在 std::reference_wrapper 中的引用类型
(类模板)
特征操作
变参逻辑与元函数
(类模板)
变参逻辑或元函数
(类模板)
(C++17)
逻辑非元函数
(类模板)

函数

成员关系
检查类型的对象是否与该类型的指定子对象 指针可互转换
(函数模板)
检查两个指定成员在两种指定类型的公共初始子序列中是否相互对应
(函数模板)
常量求值上下文
检测函数调用是否发生在常量求值上下文中
(函数)
检查指针是否在编译时处于对象的生命周期内
(函数)

概要

namespace std {
  // helper class
  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;
  // logical operator traits
  template<class... B> struct conjunction;
  template<class... B> struct disjunction;
  template<class B> struct negation;
  // 基础类型分类
  template<class T>
    inline constexpr bool is_void_v = is_void<T>::;
  template<class T>
    inline constexpr bool is_null_pointer_v = is_null_pointer<T>::;
  template<class T>
    inline constexpr bool is_integral_v = is_integral<T>::;
  template<class T>
    inline constexpr bool is_floating_point_v = is_floating_point<T>::;
  template<class T>
    inline constexpr bool is_array_v = is_array<T>::;
  template<class T>
    inline constexpr bool is_pointer_v = is_pointer<T>::;
  template<class T>
    inline constexpr bool is_lvalue_reference_v = is_lvalue_reference<T>::;
  template<class T>
    inline constexpr bool is_rvalue_reference_v = is_rvalue_reference<T>::;
  template<class T>
    inline constexpr bool is_member_object_pointer_v = is_member_object_pointer<T>::;
  template<class T>
    inline constexpr bool is_member_function_pointer_v = is_member_function_pointer<T>::;
  template<class T>
    inline constexpr bool is_enum_v = is_enum<T>::;
  template<class T>
    inline constexpr bool is_union_v = is_union<T>::;
  template<class T>
    inline constexpr bool is_class_v = is_class<T>::;
  template<class T>
    inline constexpr bool is_function_v = is_function<T>::;
  // 复合类型类别
  template<class T>
    inline constexpr bool is_reference_v = is_reference<T>::;
  template<class T>
    inline constexpr bool is_arithmetic_v = is_arithmetic<T>::;
  template<class T>
    inline constexpr bool is_fundamental_v = is_fundamental<T>::;
  template<class T>
    inline constexpr bool is_object_v = is_object<T>::;
  template<class T>
    inline constexpr bool is_scalar_v = is_scalar<T>::;
  template<class T>
    inline constexpr bool is_compound_v = is_compound<T>::;
  template<class T>
    inline constexpr bool is_member_pointer_v = is_member_pointer<T>::;
  // 类型属性
  template<class T>
    inline constexpr bool is_const_v = is_const<T>::;
  template<class T>
    inline constexpr bool is_volatile_v = is_volatile<T>::;
  template<class T>
    inline constexpr bool is_trivial_v = is_trivial<T>::;
  template<class T>
    inline constexpr bool is_trivially_copyable_v = is_trivially_copyable<T>::;
  template<class T>
    inline constexpr bool is_standard_layout_v = is_standard_layout<T>::;
  template<class T>
    inline constexpr bool is_empty_v = is_empty<T>::;
  template<class T>
    inline constexpr bool is_polymorphic_v = is_polymorphic<T>::;
  template<class T>
    inline constexpr bool is_abstract_v = is_abstract<T>::;
  template<class T>
    inline constexpr bool is_final_v = is_final<T>::;
  template<class T>
    inline constexpr bool is_aggregate_v = is_aggregate<T>::;
  template<class T>
    inline constexpr bool is_signed_v = is_signed<T>::;
  template<class T>
    inline constexpr bool is_unsigned_v = is_unsigned<T>::;
  template<class T>
    inline constexpr bool is_bounded_array_v = is_bounded_array<T>::;
  template<class T>
    inline constexpr bool is_unbounded_array_v = is_unbounded_array<T>::;
  template<class T>
    inline constexpr bool is_scoped_enum_v = is_scoped_enum<T>::;
  template<class T, class... Args>
    inline constexpr bool is_constructible_v = is_constructible<T, Args...>::;
  template<class T>
    inline constexpr bool is_default_constructible_v = is_default_constructible<T>::;
  template<class T>
    inline constexpr bool is_copy_constructible_v = is_copy_constructible<T>::;
  template<class T>
    inline constexpr bool is_move_constructible_v = is_move_constructible<T>::;
  template<class T, class U>
    inline constexpr bool is_assignable_v = is_assignable<T, U>::;
  template<class T>
    inline constexpr bool is_copy_assignable_v = is_copy_assignable<T>::;
  template<class T>
    inline constexpr bool is_move_assignable_v = is_move_assignable<T>::;
  template<class T, class U>
    inline constexpr bool is_swappable_with_v = is_swappable_with<T, U>::;
  template<class T>
    inline constexpr bool is_swappable_v = is_swappable<T>::;
  template<class T>
    inline constexpr bool is_destructible_v = is_destructible<T>::;
  template<class T, class... Args>
    inline constexpr bool is_trivially_constructible_v
      = is_trivially_constructible<T, Args...>::;
  template<class T>
    inline constexpr bool is_trivially_default_constructible_v
      = is_trivially_default_constructible<T>::;
  template<class T>
    inline constexpr bool is_trivially_copy_constructible_v
      = is_trivially_copy_constructible<T>::;
  template<class T>
    inline constexpr bool is_trivially_move_constructible_v
      = is_trivially_move_constructible<T>::;
  template<class T, class U>
    inline constexpr bool is_trivially_assignable_v = is_trivially_assignable<T, U>::;
  template<class T>
    inline constexpr bool is_trivially_copy_assignable_v
      = is_trivially_copy_assignable<T>::;
  template<class T>
    inline constexpr bool is_trivially_move_assignable_v
      = is_trivially_move_assignable<T>::;
  template<class T>
    inline constexpr bool is_trivially_destructible_v = is_trivially_destructible<T>::;
  template<class T, class... Args>
    inline constexpr bool is_nothrow_constructible_v
      = is_nothrow_constructible<T, Args...>::;
  template<class T>
    inline constexpr bool is_nothrow_default_constructible_v
      = is_nothrow_default_constructible<T>::;
  template<class T>
    inline constexpr bool is_nothrow_copy_constructible_v
      = is_nothrow_copy_constructible<T>::;
  template<class T>
    inline constexpr bool is_nothrow_move_constructible_v
      = is_nothrow_move_constructible<T>::;
  template<class T, class U>
    inline constexpr bool is_nothrow_assignable_v = is_nothrow_assignable<T, U>::;
  template<class T>
    inline constexpr bool is_nothrow_copy_assignable_v = is_nothrow_copy_assignable<T>::;
  template<class T>
    inline constexpr bool is_nothrow_move_assignable_v = is_nothrow_move_assignable<T>::;
  template<class T, class U>
    inline constexpr bool is_nothrow_swappable_with_v = is_nothrow_swappable_with<T, U>::;
  template<class T>
    inline constexpr bool is_nothrow_swappable_v = is_nothrow_swappable<T>::;
  template<class T>
    inline constexpr bool is_nothrow_destructible_v = is_nothrow_destructible<T>::;
  template<class T>
    inline constexpr bool has_virtual_destructor_v = has_virtual_destructor<T>::;
  template<class T>
    inline constexpr bool has_unique_object_representations_v
      = has_unique_object_representations<T>::;
  template<class T, class U>
    inline constexpr bool reference_constructs_from_temporary_v
      = reference_constructs_from_temporary<T, U>::;
  template<class T, class U>
    inline constexpr bool reference_converts_from_temporary_v
      = reference_converts_from_temporary<T, U>::;
  // 类型属性查询
  template<class T>
    inline constexpr size_t alignment_of_v = alignment_of<T>::;
  template<class T>
    inline constexpr size_t rank_v = rank<T>::;
  template<class T, unsigned I = 0>
    inline constexpr size_t extent_v = extent<T, I>::;
  // 类型关系
  template<class T, class U>
    inline constexpr bool is_same_v = is_same<T, U>::;
  template<class Base, class Derived>
    inline constexpr bool is_base_of_v = is_base_of<Base, Derived>::;
  template<class Base, class Derived>
    inline constexpr bool is_virtual_base_of_v = is_virtual_base_of<Base, Derived>::;
  template<class From, class To>
    inline constexpr bool is_convertible_v = is_convertible<From, To>::;
  template<class From, class To>
    inline constexpr bool is_nothrow_convertible_v = is_nothrow_convertible<From, To>::;
  template<class T, class U>
    inline constexpr bool is_layout_compatible_v = is_layout_compatible<T, U>::;
  template<class Base, class Derived>
    inline constexpr bool is_pointer_interconvertible_base_of_v
      = is_pointer_interconvertible_base_of<Base, Derived>::;
  template<class Fn, class... ArgTypes>
    inline constexpr bool is_invocable_v = is_invocable<Fn, ArgTypes...>::;
  template<class R, class Fn, class... ArgTypes>
    inline constexpr bool is_invocable_r_v = is_invocable_r<R, Fn, ArgTypes...>::;
  template<class Fn, class... ArgTypes>
    inline constexpr bool is_nothrow_invocable_v = is_nothrow_invocable<Fn, ArgTypes...>::;
  template<class R, class Fn, class... ArgTypes>
    inline constexpr bool is_nothrow_invocable_r_v
      = is_nothrow_invocable_r<R, Fn, ArgTypes...>::;
  // logical operator traits
  template<class... B>
    inline constexpr bool conjunction_v = conjunction<B...>::;
  template<class... B>
    inline constexpr bool disjunction_v = disjunction<B...>::;
  template<class B>
    inline constexpr bool negation_v = negation<B>::;
  // 成员关系
  template<class S, class M>
    constexpr bool is_pointer_interconvertible_with_class(M S::*m) noexcept;
  template<class S1, class S2, class M1, class M2>
    constexpr bool is_corresponding_member(M1 S1::*m1, M2 S2::*m2) noexcept;
  // 常量求值上下文
  constexpr bool is_constant_evaluated() noexcept;
  consteval bool is_within_lifetime(const auto*) noexcept;
}

类模板 std::integral_constant

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