GF2::Vector — Change Elements via Function Value

Methods to set or flip the element values in a bit-vector based on the return value from a function call.

constexpr Vector &set_if(std::invocable<std::size_t, std::size_t> auto f);    (1)
constexpr Vector &flip_if(std::invocable<std::size_t, std::size_t> auto f);   (2)
1 Sets element i to 1 if f(i) != 0, otherwise sets it to 0.
2 Flips the value of element i if f(i) != 0, otherwise leaves it unchanged.

f is a function that we expect to call as f(i) for each index.

Returns

Both methods return a reference to *this so can be chained with other calls.

Example
#include <GF2/GF2.h>
int main()
{
    GF2::Vector<> v(32);                                    (1)
    std::cout << "v: " << v << '\n';
    v.set_if([](std::size_t i) { return (i + 1) % 2; });    (2)
    std::cout << "v: " << v << '\n';
    v.flip_if([](std::size_t i) { return (i + 1) % 2; });   (3)
    std::cout << "v: " << v << '\n';
}
1 Start with a bit-vector whose elements are all 0 by default.
2 Using the set_if method with a lambda to set the even indices 0,2,4,…​
3 Using the flip_if method with a lambda to flip the even indices 0,2,4,…​
Output
v: 00000000000000000000000000000000
v: 10101010101010101010101010101010
v: 00000000000000000000000000000000
See Also

set`
reset
flip