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,
1 const bit::vector<Block, Alloc> &rhs);
operator^(const bit::vector<Block, Alloc> &lhs,
2 const bit::vector<Block, Alloc> &rhs);
operator|(const bit::vector<Block, Alloc> &lhs,
3 const bit::vector<Block, Alloc> &rhs);
operator+(const bit::vector<Block, Alloc> &lhs,
4 const bit::vector<Block, Alloc> &rhs);
operator-(const bit::vector<Block, Alloc> &lhs,
5 const bit::vector<Block, Alloc> &rhs);
operator*(const bit::vector<Block, Alloc> &lhs,
6 const bit::vector<Block, Alloc> &rhs);- 1
-
Returns a bit-vector whose bits result from binary
ANDbetween the corresponding pairs of bits ofrhsandlhs. - 2
-
Returns a bit-vector whose bits result from binary
XORbetween the corresponding pairs of bits ofrhsandlhs. - 3
-
Returns a bit-vector whose bits result from binary
ORbetween the corresponding pairs of bits ofrhsandlhs. - 4
-
Returns a bit-vector whose bits result from binary
XORbetween the corresponding pairs of bits ofrhsandlhs.
In GF(2), addition corresponds to the logicalXORoperation. - 5
-
Returns a bit-vector whose bits result from binary
XORbetween the corresponding pairs of bits ofrhsandlhs.
In GF(2), subtraction corresponds to the logicalXORoperation. - 6
-
Returns a bit-vector whose bits result from binary
ANDbetween the corresponding pairs of bits ofrhsandlhs.
In GF(2), multiplication corresponds to the logicalANDoperation.
|
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 bit::vector<> u(11, [&](size_t k) { return k % 2; });
2 bit::vector<> v(11, [&](size_t k) { return (k + 1) % 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
[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*=