目录

bit_and

描述 (Description)

它是一个按位AND函数对象类和二进制函数对象类,其调用返回在其两个参数之间应用按位“和”操作的结果(由operator&返回)。

声明 (Declaration)

以下是std :: bit_and的声明。

template <class T> struct bit_and;

C++11

template <class T> struct bit_and;

参数 (Parameters)

T - 它是函数调用的参数和返回类型的一种类型。

返回值 (Return Value)

没有

异常 (Exceptions)

noexcep - 它不会抛出任何异常。

例子 (Example)

在下面的例子中解释了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    
↑回到顶部↑
WIKI教程 @2018