否定std :: integral_constant< bool> [英] negation of std::integral_constant<bool>

查看:259
本文介绍了否定std :: integral_constant< bool>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于这么简单的问题,很抱歉,但我找不到答案很容易。 Google对于C ++ negation integral_constant和类似的查询没有什么有趣的。

Sorry for asking so simple question, but I cannot find the answer easily. Google says nothing interesting about "C++ negation integral_constant" and similar queries.

在C ++ 11中有任何特性使 std :: true_type std :: false_type ,反之亦然?换句话说,我想要更多的readeble版本

Is there in C++11 any trait that make std::true_type from std::false_type and vice versa? In other words, I'd like some more readeble version of

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

我知道当然可以自己写,但是我想使用现有的if有这样的。

I know of course I can write it myself, but I'd like to use the existing one if there is such.

推荐答案

没有,因为它本质上是一行和 type_traits> 应尽可能小。

There is not, because it's essentially a one-liner and the <type_traits> should be as small as possible.

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

用法:

static_not<my_static_bool>

这是正确的方法,因为标准总是说 false_type 或派生自这样的,所以你不能依赖于等于 std :: false_type 。我通常放松到有一个constexpr布尔 :: value 属性,因为我不使用标签调度。

This is the correct way because the standard always says "false_type or derived from such", so you can't depend on being equal to std::false_type. I usually relax that to "having a constexpr boolean ::value property" because I don't use tag dispatching.

这篇关于否定std :: integral_constant&lt; bool&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆