C++ 函式庫 - bit_and



描述

它是一個按位與函式物件類和二元函式物件類,其呼叫返回對其兩個引數應用按位“與”運算的結果(如運算子 & 所返回的那樣)。

宣告

以下是 std::bit_and 的宣告。

template <class T> struct bit_and;

C++11

template <class T> struct bit_and;

引數

T − 它表示函式呼叫引數和返回型別的型別。

返回值

異常

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    
functional.htm
廣告