GF2++
Loading...
Searching...
No Matches
gf2::BitRef< Store >

A BitRef is a proxy class to reference a single bit in a bit-store. More...

#include <BitRef.h>

Public Member Functions

 BitRef (BitStore< Store > *store, usize index)
 Constructs a reference to the bit at index in the given BitStore.
constexpr operator bool () const
 Returns the boolean value of the bit at index in the referenced bit-store.
constexpr BitRefoperator= (bool rhs)
 Sets the bit at index in the referenced bit-store to the given value.
constexpr BitRefoperator= (const BitRef &rhs)
 Sets the bit at index in the referenced bit-store to the value of the given BitRef.
constexpr BitRefflip ()
 Flips the bit at index in the referenced bit-store.
constexpr BitRefoperator&= (bool rhs)
 Performs an AND operation on the bit at index in the referenced bit-store with rhs.
constexpr BitRefoperator&= (const BitRef &rhs)
 Performs an AND operation on the bit at index in the referenced bit-store with rhs.
constexpr BitRefoperator|= (bool rhs)
 Performs an OR operation on the bit at index in the referenced bit-store with rhs.
constexpr BitRefoperator|= (const BitRef &rhs)
 Performs an OR operation on the bit at index in the referenced bit-store with rhs.
constexpr BitRefoperator^= (bool rhs)
 Performs an XOR operation on the bit at index in the referenced bit-store with rhs.
constexpr BitRefoperator^= (const BitRef &rhs)
 Performs an XOR operation on the bit at index in the referenced bit-store with rhs.

Detailed Description

template<typename Store>
class gf2::BitRef< Store >

A BitRef is a proxy class to reference a single bit in a bit-store.

If v is any non-const bit-store then v[i] is a BitRef that references the bit at index i in v. It behaves as a proxy for that element and allows us to set or get the bit value via the = operator.

The end user can also treat the BitRef object as a reference to a boolean value and use it in boolean expressions.

Note
The underlying bit-store must live as long as the BitRef that refers to it.

Example

BitVec v{3};
assert_eq(v.to_string(), "000");
v[1] = true;
assert_eq(v.to_string(), "010");
v[2] = 1;
assert_eq(v.to_string(), "011");
std::string to_string(std::string_view sep="", std::string_view pre="", std::string_view post="") const
Returns a binary string representation of the store.
Definition BitStore.h:1606
A dynamically-sized vector over GF(2) with bit elements compactly stored in a standard vector of prim...
Definition BitVec.h:37