GF2++
Loading...
Searching...
No Matches
gf2::BitsIter< 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<typename Store, bool is_const>
class gf2::BitsIter< 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.

  • BitsIter<Store, Word, false>: A non-const iterator over the bits in a bit-store (value type is BitRef).
  • BitsIter<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

BitVec v{10};
assert_eq(v.to_string(), "0000000000");
for (auto&& bit : v.bits()) bit = true;
assert_eq(v.to_string(), "1111111111");
constexpr auto bits() const
Returns a const iterator over the bool values of the bits in the const bit-store.
Definition BitStore.h:945
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