GF2::Vector — Iterate over the Set Bits
Iterate over the elements in a bit-vector calling a function f(i) for every index i where the corresponding element is 1.
constexpr void if_set_call(std::invocable<std::size_t> auto f) const; (1)
constexpr void reverse_if_set_call(std::invocable<std::size_t> auto f) const; (2)
| 1 | The iteration here is in the order vector.first() forward to vector.last(). |
| 2 | The iteration here is in the order vector.last() backward to vector.first(). |
| Template Parameter | |
|---|---|
|
|
Parameters |
|
|
For each set element index |
Example
#include <GF2/GF2.h>
int main()
{
GF2::Vector<> v(11, [&](size_t k) { return (k + 1) % 2; }); (1)
std::cout << "The set indices in " << v << " are ";
v.if_set_call([](std::size_t k) { std::cout << k << ' '; }); (2)
std::cout << std::endl;
}
| 1 | Creates a vector of size 11 by calling a lambda that sets all the even indices. |
| 2 | The trivial print to std::cout lambda only get called if the corresponding element in v is set. |
Output
The set indices in 10101010101 are 0 2 4 6 8 10