命名空间
变体
操作

std::bit_and

来自 cppreference.cn
< cpp‎ | utility‎ | functional
 
 
 
函数对象
函数调用
(C++17)(C++23)
恒等函数对象
(C++20)
透明运算符包装器
(C++14)
(C++14)
(C++14)
(C++14)  
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)

旧式绑定器和适配器
(直到 C++17*)
(直到 C++17*)
(直到 C++17*)
(直到 C++17*)  
(直到 C++17*)
(直到 C++17*)(直到 C++17*)(直到 C++17*)(直到 C++17*)
(直到 C++20*)
(直到 C++20*)
(直到 C++17*)(直到 C++17*)
(直到 C++17*)(直到 C++17*)

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

用于执行按位与操作的函数对象。 有效地在类型 T 上调用 operator&

内容

[编辑] 特化

标准库在未指定 T 时提供了 std::bit_and 的特化,这使得参数类型和返回类型能够被推导。

实现 x & y 的函数对象,推导参数和返回类型
(类模板特化) [编辑]
(自 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_and::operator()

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

返回 lhsrhs 按位与的结果。

参数

lhs, rhs - 用于计算按位与的值

返回值

lhs & rhs 的结果。

[编辑] 异常

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

可能的实现

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

[编辑] 缺陷报告

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

DR 应用于 已发布行为 正确行为
LWG 660 C++98 按位运算的函数对象缺失 已添加