bit::vector
— Logical Op Operators
These are non-member functions to perform element-by-element binary AND
, XOR
, OR
, DIFF
between two equal-sized bit-vectors.
template<std::unsigned_integral Block, typename Alloc>
constexpr bit::vector<Block, Alloc>
operator&(const bit::vector<Block, Alloc> &lhs,
1const bit::vector<Block, Alloc> &rhs);
operator^(const bit::vector<Block, Alloc> &lhs,
2const bit::vector<Block, Alloc> &rhs);
operator|(const bit::vector<Block, Alloc> &lhs,
3const bit::vector<Block, Alloc> &rhs);
operator+(const bit::vector<Block, Alloc> &lhs,
4const bit::vector<Block, Alloc> &rhs);
operator-(const bit::vector<Block, Alloc> &lhs,
5const bit::vector<Block, Alloc> &rhs);
operator*(const bit::vector<Block, Alloc> &lhs,
6const bit::vector<Block, Alloc> &rhs);
- 1
-
Returns a bit-vector whose bits result from binary
AND
between the corresponding pairs of bits ofrhs
andlhs
. - 2
-
Returns a bit-vector whose bits result from binary
XOR
between the corresponding pairs of bits ofrhs
andlhs
. - 3
-
Returns a bit-vector whose bits result from binary
OR
between the corresponding pairs of bits ofrhs
andlhs
. - 4
-
Returns a bit-vector whose bits result from binary
XOR
between the corresponding pairs of bits ofrhs
andlhs
.
In GF(2), addition corresponds to the logicalXOR
operation. - 5
-
Returns a bit-vector whose bits result from binary
XOR
between the corresponding pairs of bits ofrhs
andlhs
.
In GF(2), subtraction corresponds to the logicalXOR
operation. - 6
-
Returns a bit-vector whose bits result from binary
AND
between the corresponding pairs of bits ofrhs
andlhs
.
In GF(2), multiplication corresponds to the logicalAND
operation.
The two vectors in question must be of the same size. Set the BIT_VERIFY flag at compile time to check this condition — any violation will cause the program to abort with a helpful message.
|
Example
#include <bit/bit.h>
int main()
{
1::vector<> u(11, [&](size_t k) { return k % 2; });
bit2::vector<> v(11, [&](size_t k) { return (k + 1) % 2; });
bitstd::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
[0 1 0 1 0 1 0 1 0 1 0] & [1 0 1 0 1 0 1 0 1 0 1] = [0 0 0 0 0 0 0 0 0 0 0]
[0 1 0 1 0 1 0 1 0 1 0] ^ [1 0 1 0 1 0 1 0 1 0 1] = [1 1 1 1 1 1 1 1 1 1 1]
[0 1 0 1 0 1 0 1 0 1 0] | [1 0 1 0 1 0 1 0 1 0 1] = [1 1 1 1 1 1 1 1 1 1 1]
See Also
vector::operator&=
{vec.operator=|}
vector::operator^=
vector::operator+=
vector::operator-=
vector::operator*=