Namespaces
Variants

std:: bit_xor

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 >
struct bit_xor ;
(C++14 前)
template < class T = void >
struct bit_xor ;
(C++14 起)

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

目录

特化

当未指定 T 时,标准库提供了 std::bit_xor 的特化版本,该版本会推导参数类型和返回类型。

实现 x ^ y 并推导参数和返回类型的函数对象
(类模板特化)
(since C++14)

成员类型

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

这些成员类型通过公开继承 std:: binary_function < T, T, T > 获得。

(C++11 前)

成员函数

operator()
返回两个参数的按位异或结果
(公开成员函数)

std::bit_xor:: operator()

T operator ( ) ( const T & lhs, const T & rhs ) const ;
(constexpr since C++14)

返回 lhs rhs 的按位异或结果。

参数

lhs, rhs - 要计算按位异或的值

返回值

lhs ^ rhs 的结果。

异常

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

可能的实现

constexpr T operator()(const T& lhs, const T& rhs) const
{
    return lhs ^ rhs;
}

缺陷报告

下列行为变更缺陷报告被追溯应用于先前发布的C++标准。

缺陷报告 应用于 发布时的行为 正确行为
LWG 660 C++98 缺少用于位运算的函数对象 已添加