(24) is_array_v , 本头文件用到了这个模板类,学习以下:
template <class> // determine whether type argument is an array
bool is_array_v = false;
template <class _Ty, size_t _Nx>
bool is_array_v<_Ty[_Nx]> = true;
template <class _Ty>
bool is_array_v<_Ty[]> = true;
template <class _Ty>
struct is_array : bool_constant<is_array_v<_Ty>> {};
++ 测试结果如下:
(25) is_const_v、is_function_v、is_object_v,这几个定义在本头文件,也会用到。给出其源码定义:
template <class>
bool is_reference_v = false; // determine whether type argument is a reference
template <class _Ty>
bool is_reference_v<_Ty&> = true;
template <class _Ty>
bool is_reference_v<_Ty&&> = true;
//--------------------------------------------------------------------
template <class>
bool is_const_v = false; // determine whether type argument is const qualified
template <class _Ty> // 若类型被 const 修饰,则为 true 。但也有编译器规定的例外情形
bool is_const_v<const _Ty> = true; // 函数类型和引用类型就是被 const 修饰,也是 False
//-----------------------------------------------------------------
// only function types and reference types can't be const qualified
template <class _Ty>
bool is_function_v = !is_const_v<const _Ty> && !is_reference_v<_Ty>;
template <class _Ty> // 这就排除了函数类型与引用类型,又非 void ,即为所谓的对象类型
bool is_object_v = is_const_v<const _Ty> && !is_void_v<_Ty>;
++ 测试结果如下:
++ 在源码的这里有应用:
(26)接着学习上图中的 is_destructible_v 可析构类型,源码引用了更底层的判断逻辑,没有大的参考意义,接着测试一下:
template <class _Ty> // < type_traits > 头文件
_INLINE_VAR constexpr bool is_destructible_v = __is_destructible(_Ty);
++ 测试一下:
(27)
谢谢