2023年8月10日,周四上午
C++中的类型查询(type trait)模板用于提供关于类型特征的信息,
帮助在编译期间进行类型检查和类型推导。
这些类型查询模板都定义在 <type_traits> 头文件中
常见的类型查询模板
std::is_array<T>:用于判断类型T是否是数组类型。std::is_pointer<T>:用于判断类型T是否是指针类型。std::is_reference<T>:用于判断类型T是否是引用类型。std::is_const<T>:用于判断类型T是否是常量类型。std::is_volatile<T>:用于判断类型T是否是易失类型。std::is_integral<T>:用于判断类型T是否是整数类型。std::is_floating_point<T>:用于判断类型T是否是浮点类型。std::is_enum<T>:用于判断类型T是否是枚举类型。std::is_class<T>:用于判断类型T是否是类类型。std::is_function<T>:用于判断类型T是否是函数类型。std::is_void<T>:用于判断类型T是否是void类型。std::is_same<T, U>:用于判断类型T和类型U是否相同。std::is_base_of<Base, Derived>:用于判断类型Derived是否是类型Base的派生类。std::is_convertible<T, U>:用于判断类型T是否可隐式转换为类型U。std::is_trivial<T>:用于判断类型T是否是平凡类型。std::is_pod<T>:用于判断类型T是否是POD类型(Plain Old Data)。std::is_abstract<T>:用于判断类型T是否是抽象类类型。std::is_default_constructible<T>:用于判断类型T是否具有默认构造函数。std::is_copy_constructible<T>:用于判断类型T是否具有复制构造函数。std::is_move_constructible<T>:用于判断类型T是否具有移动构造函数。