std::negation
来自cppreference.com
<tbody>
</tbody>
| 在标头 <type_traits> 定义
|
||
template< class B > struct negation; |
(C++17 起) | |
构建类型特征 B 的逻辑反。
类型 std::negation<B> 是基特征为 std::bool_constant<!bool(B::value)> 的一元类型特征 (UnaryTypeTrait) 。
如果程序添加了 std::negation 或 std::negation_v 的特化,那么行为未定义。
模板形参
| B | - | 使得表达式 bool(B::value) 为合法常量表达式的任何类型
|
辅助变量模板
<tbody> </tbody> template< class B > constexpr bool negation_v = negation<B>::value; |
(C++17 起) | |
继承自 std::integral_constant
成员常量
value [静态] |
如果 B 拥有在隐式转换为 bool 时等于 false 的 ::value那么是 true,否则是 false (公开静态成员常量) |
成员函数
operator bool |
将对象转换到 bool,返回 value (公开成员函数) |
operator() (C++14) |
返回 value (公开成员函数) |
成员类型
| 类型 | 定义 |
value_type
|
bool
|
type
|
std::integral_constant<bool, value>
|
可能的实现
template<class B>
struct negation : std::bool_constant<!bool(B::value)> { };
|
注解
| 功能特性测试宏 | 值 | 标准 | 功能特性 |
|---|---|---|---|
__cpp_lib_logical_traits |
201510L |
(C++17) | 逻辑运算符类型特征 |
示例
运行此代码
#include <type_traits>
static_assert(
std::is_same<
std::bool_constant<false>,
typename std::negation<std::bool_constant<true>>::type>::value,
"");
static_assert(
std::is_same<
std::bool_constant<true>,
typename std::negation<std::bool_constant<false>>::type>::value,
"");
static_assert(std::negation_v<std::bool_constant<true>> == false);
static_assert(std::negation_v<std::bool_constant<false>> == true);
int main() {}
参阅
(C++17) |
变参的逻辑与元函数 (类模板) |
(C++17) |
变参的逻辑或元函数 (类模板) |
(C++11)(C++17) |
具有指定值的指定类型的编译期常量 (类模板) |