GF2::Vector — Logical Op= Operators
Methods to perform element-by-element binary AND, XOR, OR with another equal sized bit-vector.
constexpr Vector &operator&=(const Vector &other); (1)
constexpr Vector &operator^=(const Vector &other); (2)
constexpr Vector &operator|=(const Vector &other); (3)
constexpr Vector &operator+=(const Vector &other); (4)
constexpr Vector &operator-=(const Vector &other); (5)
constexpr Vector &operator*=(const Vector &other); (6)
| 1 | Sets this bit-vector’s bits to the result of binary AND between the corresponding pairs of bits of *this and other. |
| 2 | Sets this bit-vector’s bits to the result of binary XOR between the corresponding pairs of bits of *this and other. |
| 3 | Sets this bit-vector’s bits to the result of binary OR between the corresponding pairs of bits of *this and other. |
| 4 | Sets this bit-vector’s bits to the result of binary XOR between the corresponding pairs of bits of *this and other.
In GF(2) addition corresponds to the logical XOR operation. |
| 5 | Sets this bit-vector’s bits to the result of binary XOR between the corresponding pairs of bits of *this and other.
In GF(2) subtraction also corresponds to the logical XOR operation. |
| 6 | Sets this bit-vector’s bits to the result of binary AND between the corresponding pairs of bits of *this and other.
In GF(2) multiplication corresponds to the logical AND operation. |
These methods all return a reference to *this so they can be chained with other calls.
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.
|
constexpr Vector operator~() const; (1)
| 1 | Returns a copy of the bit-vector with all the bits flipped |
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: " << u << '\n';
std::cout << "v: " << v << '\n';
std::cout << "(u &= v): " << (u &= v) << '\n';
std::cout << "(u |= v): " << (u |= v) << '\n';
std::cout << "(u ^= v): " << (u ^= v) << '\n';
std::cout << "~u: " << ~u << '\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
u: 01010101010
v: 10101010101
(u &= v): 00000000000
(u |= v): 10101010101
(u ^= v): 00000000000
~u: 11111111111