-------

//满足参数至少两个时才会被选择。当满足参数至少两个2个时第一个参数为true就会被选择。或者只有两个参数,因为下边偏特化版本需要三个参数。
template <bool _First_value, class _First, class... _Rest>
struct _Conjunction { // handle false trait or last trait
    using type = _First;
};
//对上一个进行了偏特化。偏特化出第三个参数和第一个参数是true。只有满足参数大于2个第一个参数为true时才会被调用,否则调用非特化版本。
template <class _True, class _Next, class... _Rest>
struct _Conjunction<true, _True, _Next, _Rest...> { // the first trait is true, try the next one
    using type = typename _Conjunction<_Next::value, _Next, _Rest...>::type;
};
//对_Conjunction数据进行过滤,当参数个数为0个时默认返回true_type
template <class... _Traits>
struct conjunction : true_type {}; // If _Traits is empty, true_type
//对_Conjunction数据进行过滤,当参数个数大于0个时利用继承方式去处理。最后获取到false_type或者true_type。
template <class _First, class... _Rest>
struct conjunction<_First, _Rest...> : _Conjunction<_First::value, _First, _Rest...>::type {
    // the first false trait in _Traits, or the last trait if none are false
};
//获取false或者true,当里边有false时为false,没有就为true
template <class... _Traits>
_INLINE_VAR constexpr bool conjunction_v = conjunction<_Traits...>::value;
//取相反的值。利用继承获得bool_constant类型。
template <class _Trait>
struct negation : bool_constant<!static_cast<bool>(_Trait::value)> {}; // The negated result of _Trait
//获取最后的结果。false或者true
template <class _Trait>
_INLINE_VAR constexpr bool negation_v = negation<_Trait>::value;
//判断是不是void,利用remove_cv_t,去除掉const和volatile(利用模板会优先匹配到特化版本)
//然后再利用is_same_v(利用特化变量is_same<_ty, _ty> = true)比较_Ty和void是不是一种类型。
template <class _Ty>
_INLINE_VAR constexpr bool is_void_v = is_same_v<remove_cv_t<_Ty>, void>;
//继承bool_constant,最后变成false_type或者true_type;
template <class _Ty>
struct is_void : bool_constant<is_void_v<_Ty>> {};
// 添加const属性,去除原来所有属性(const volatile & &&),添加上const,并重新定义一个新的类型
template <class _Ty>
struct add_const { // add top-level const qualifier
    using type = const _Ty;
};
//对类型重新定义成统一格式_t
template <class _Ty>
using add_const_t = typename add_const<_Ty>::type;
//添加volatile属性,去除原来所有属性(const volatile & &&),添加上volatile,并重新定义一个新的类型
template <class _Ty>
struct add_volatile { // add top-level volatile qualifier
    using type = volatile _Ty;
};
//对类型重新定义成统一格式_t
template <class _Ty>
using add_volatile_t = typename add_volatile<_Ty>::type;
//添加const volatile属性,去除原来所有属性(const volatile & &&),添加上const volatile,并重新定义一个新的类型
template <class _Ty>
struct add_cv { // add top-level const and volatile qualifiers
    using type = const volatile _Ty;
};
//对类型重新定义成统一格式_t
template <class _Ty>
using add_cv_t = typename add_cv<_Ty>::type;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值