Suppose I have two vectors std::vector<uint_32> a, b;
that I know to be of the same size.
Is there a C++11 paradigm for doing a bitwise-AND
between all members of a
and b
, and putting the result in std::vector<uint_32> c;
?
A lambda should do the trick:
#include <algorithm>
#include <iterator>
std::transform(a.begin(), a.end(), // first
b.begin(), // second
std::back_inserter(c), // output
[](uint32_t n, uint32_t m) { return n & m; } );
Even better, thanks to @Pavel and entirely C++98:
#include <functional>
std::transform(a.begin(), a.end(), b.begin(),
std::back_inserter(c), std::bit_and<uint32_t>());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With