C++ 函式庫 - bit_xor



描述

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

宣告

以下是 std::bit_xor 的宣告。

template <class T> struct bit_xor;

C++11

template <class T> struct bit_xor;

引數

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

返回值

異常

noexcep − 它不丟擲任何異常。

示例

以下示例說明了 std::bit_xor。

#include <iostream>     
#include <functional>   
#include <algorithm>    
#include <iterator>     

int main () {
   int flags[] = {10,20,30,40,50,60,70,80,90,100};
   int acc = std::accumulate (flags, std::end(flags), 0, std::bit_xor<int>());
   std::cout << "xor: " << acc << '\n';
   return 0;
}

讓我們編譯並執行上述程式,這將產生以下結果:

xor: 14  
functional.htm
廣告

© . All rights reserved.