GF2::Vector — Logical Op Operators

Methods to perform element-by-element binary AND, XOR, OR, DIFF between two equal sized bit-vectors.

template<std::unsigned_integral Block, typename Alloc>
constexpr GF2::Vector<Block, Alloc>
operator&(const GF2::Vector<Block, Alloc> &lhs,
          const GF2::Vector<Block, Alloc> &rhs);    (1)
operator^(const GF2::Vector<Block, Alloc> &lhs,
          const GF2::Vector<Block, Alloc> &rhs);    (2)
operator|(const GF2::Vector<Block, Alloc> &lhs,
          const GF2::Vector<Block, Alloc> &rhs);    (3)
operator+(const GF2::Vector<Block, Alloc> &lhs,
          const GF2::Vector<Block, Alloc> &rhs);    (4)
operator-(const GF2::Vector<Block, Alloc> &lhs,
          const GF2::Vector<Block, Alloc> &rhs);    (5)
operator*(const GF2::Vector<Block, Alloc> &lhs,
          const GF2::Vector<Block, Alloc> &rhs);    (6)
1 Returns a bit-vector whose bits are the result of binary AND between the corresponding pairs of bits of rhs and lhs.
2 Returns a bit-vector whose bits are the result of binary XOR between the corresponding pairs of bits of rhs and lhs.
3 Returns a bit-vector whose bits are the result of binary OR between the corresponding pairs of bits of rhs and lhs.
4 Returns a bit-vector whose bits are the result of binary XOR between the corresponding pairs of bits of rhs and lhs. In GF(2) addition corresponds to the logical XOR operation.
5 Returns a bit-vector whose bits are the result of binary XOR between the corresponding pairs of bits of rhs and lhs. In GF(2) subtraction also corresponds to the logical XOR operation.
6 Returns a bit-vector whose bits are the result of binary AND between the corresponding pairs of bits of rhs and lhs. In GF(2) multiplication corresponds to the logical AND operation.
The two bit-vectors in question must be of the same size. If the GF2_DEBUG flag is set at compile time this is checked and any violation will cause the program to abort with a helpful message.
Example
#include <GF2/GF2.h>
int main()
{
    GF2::Vector<> u(11, [&](size_t k) { return k % 2; });       (1)
    GF2::Vector<> v(11, [&](size_t k) { return (k + 1) % 2; }); (2)
    std::cout << u << " & " << v << " = " << (u & v) << '\n';
    std::cout << u << " ^ " << v << " = " << (u ^ v) << '\n';
    std::cout << u << " | " << v << " = " << (u | v) << '\n';
}
1 Creates a vector of size 11 by calling a lambda that sets all the even indices.
2 Creates a vector of size 11 by calling a lambda that sets all the odd indices.
Output
01010101010 & 10101010101 = 00000000000
01010101010 ^ 10101010101 = 11111111111
01010101010 | 10101010101 = 11111111111