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;
?
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;
?
Just an idea, not C++11 specific: Maybe you could step through the arrays 8 bytes at a time using uint_64, even though the actual array is composed of 32-bit integers? Then you would not rely on e.g. SSE, but still get fast execution on many CPUs that have 64-bit wide registers.
A lambda should do the trick:
Even better, thanks to @Pavel and entirely C++98:
If you're going to be doing this a lot, on large arrays, check out the linear algebra libraries mentioned in https://stackoverflow.com/search?q=valarray. Many of them will take advantage of special instructions to get the answer faster.