C++ Functional 库 - bit_and
描述
它是一个按位与函数对象类和二进制函数对象类,其调用返回在其两个参数之间应用按位"与"运算的结果(由运算符 & 返回)。
声明
以下是 std::bit_and 的声明。
template <class T> struct bit_and;
C++11
template <class T> struct bit_and;
参数
T − 它是函数调用的参数类型和返回类型。
返回值
none
异常
noexcep − 它不会抛出任何异常。
示例
在下面的例子中解释了 std::bit_and。
#include <iostream>
#include <functional>
#include <algorithm>
#include <iterator>
int main () {
int values[] = {1000,2000,3000,4000,5000};
int masks[] = {0xf,0xf,0xf,255,255};
int results[5];
std::transform (values, std::end(values), masks, results, std::bit_and<int>());
std::cout << "results:";
for (const int& x: results)
std::cout << ' ' << x;
std::cout << '\n';
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 −
8 0 8 160 136

