今天遇到以一个bit_xor的情况,就是于是写了一个测试函数:
1 #include <iostream> // std::cout
2 #include <numeric>
3 #include <functional> // std::bit_xor
4 #include <algorithm> // std::accumulate
5 #include <iterator> // std::end
6 #include <vector>
7 int main () {
8 std:: vector<int>flags;
9 flags.push_back(2);
10 flags.push_back(1);
11 flags.push_back(2);
12
13 int acc = accumulate (flags.begin(), flags.end(), 0,std::bit_xor<int>());
14 std::cout << "xor: " << acc << '\n';
15 return 0;
16 }
~
~
~
这个代码的意思 就是将二进制数字进行异或操作 然后取其和