GF2++
Loading...
Searching...
No Matches
gf2::Bits< Store, is_const >

Two iterators over all the bits in a bit-store — one const and the other non-const.
The BitStore::bits() & BitStore::bits() const methods return the appropriate iterator type. More...

#include <Iterators.h>

Detailed Description

template<BitStore Store, bool is_const>
class gf2::Bits< Store, is_const >

Two iterators over all the bits in a bit-store — one const and the other non-const.
The BitStore::bits() & BitStore::bits() const methods return the appropriate iterator type.

  • Bits<Store, Word, false>: A non-const iterator over the bits in a bit-store (value type is BitRef).
  • Bits<Store, Word, true>: A const iterator over the bits in a bit-store (value type is bool).

Both iterators allow us to view the bit values but only the non-const iterator allows us to set the bit values.

The two iterator types have lots of common functionality. To avoid code duplication we add a final boolean template parameter is_const to distinguish the two types. Depending on the value of is_const, the std::conditional_t is used to choose the correct type for the store pointer and value type.

Example

BitVector v{10};
assert_eq(v.to_string(), "0000000000");
for (auto&& bit : v.bits()) bit = true;
assert_eq(v.to_string(), "1111111111");
A dynamically-sized vector over GF(2) with bit elements compactly stored in a standard vector of prim...
Definition BitVector.h:23
constexpr auto bits() const
Returns a const iterator over the bool values of the bits in the const bit-vector.
Definition BitVector.h:1544
std::string to_string(std::string_view sep="", std::string_view pre="", std::string_view post="") const
Returns a binary string representation of the bit-vector.
Definition BitVector.h:1820