<future> 注释7:is_array_v<T>,is_const_v<T>、is_function_v<T>、is_object_v<T>,is_destructible_v<T> 可析构类型

(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)

谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值