Namespaces
Variants

std:: bit_not

From cppreference.net
Utilities library
Function objects
Function invocation
(C++17) (C++23)
Identity function object
(C++20)
Old binders and adaptors
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
( until C++20* )
( until C++20* )
( until C++17* ) ( until C++17* )
( until C++17* ) ( until C++17* )

( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
( until C++20* )
( until C++20* )
定义于头文件 <functional>
template < class T = void >
struct bit_not ;
(C++14 起)

用于执行按位NOT运算的函数对象。实际上是在类型 T 上调用 operator~

目录

特化

标准库在未指定 T 时提供了 std::bit_not 的特化版本,该版本将自动推导参数类型和返回类型。

实现 ~x 的函数对象,推导参数和返回类型
(类模板特化)

成员类型

类型 定义
result_type (C++17 中弃用) (C++20 中移除) T
argument_type (C++17 中弃用) (C++20 中移除) T

成员函数

operator()
(C++14)
返回其参数的按位取反结果
(公开成员函数)

std::bit_not:: operator()

constexpr T operator ( ) ( const T & arg ) const ;
(since C++14)

返回对 arg 进行按位取反的结果。

参数

arg - 要计算按位取反的值

返回值

~arg 的结果。

异常

可能抛出由实现定义的异常。

可能的实现

constexpr T operator()(const T& arg) const
{
    return ~arg;
}

注释

尽管 std::bit_not 是通过后 C++11 提案 N3421 添加的,但常见实现将其视为对 LWG issue 660 的解决方案的一部分(除了其透明特化 std::bit_not<> ),因此在其 C++98/03 模式下也可用。