c – 否定std :: integral_constant

c – 否定std :: integral_constant,第1张

概述很抱歉问这么简单的问题,但我找不到答案.谷歌没有说“C negation integral_constant”和类似的查询. 在C 11中是否存在从std :: false_type生成std :: true_type的任何特征,反之亦然?换句话说,我想要更多的readeble版本 std::is_same<my_static_bool, std::false_type> 我当然知道我可以自己写, 很抱歉问这么简单的问题,但我找不到答案.谷歌没有说“C negation integral_constant”和类似的查询.

在C 11中是否存在从std :: false_type生成std :: true_type的任何特征,反之亦然?换句话说,我想要更多的readeble版本

std::is_same<my_static_bool,std::false_type>

我当然知道我可以自己写,但如果有的话,我想用现有的.

解决方法 没有,因为它基本上是一个单行而且< type_traits>应该尽可能小.

template <typename T> using static_not = std::integral_constant<bool,!T::value>;

用法:

static_not<my_static_bool>

这是正确的方法,因为标准总是说“false_type或从中派生”,所以你不能依赖于等于std :: false_type.我经常放松“有一个constexpr boolean :: value属性”因为我不使用标签调度.

总结

以上是内存溢出为你收集整理的c – 否定std :: integral_constant全部内容,希望文章能够帮你解决c – 否定std :: integral_constant所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1221020.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存