GF2::Vector — Element Access

Methods to access the individual elements/bits in a bit-vector.

constexpr bool element(std::size_t i) const;          (1)
constexpr reference element(std::size_t i);           (2)

constexpr bool operator[](std::size_t i) const;       (3)
constexpr reference operator[](std::size_t i);

constexpr bool operator()(std::size_t i) const;       (4)
constexpr reference operator()(std::size_t i);

constexpr bool test(std::size_t i) const;             (5)
1 Accesses the value for bit-vector element i.
2 Returns an object of type GF2::Vector::reference that allows modification of the value at index i.
3 The operator[] methods are synonyms for the element methods.
4 The operator() methods are also synonyms for the element methods. Makes it possible to have consistent access interface for bit-vectors and bit-matrices.
5 Another way to access the value for element i.
In general, these methods do not check whether the index is in bounds and if it isn’t the behavior is undefined (but sure to be bad!) All of them will perform range checking if the GF2_DEBUG flag is set at compile time. See the discussion of the gf2_debug_assert macro.
Example
#include <GF2/GF2.h>
int main()
{
    std::size_t n = 11;
    GF2::Vector<> v(n);
    std::cout << "Setting successive bits:\n";
    std::cout << v << "\n";
    for (std::size_t i = 0; i < n; ++i) {
        v[i] = 1;
        std::cout << v << "\n";
    }
    std::cout << std::endl;
}
Output
Setting successive bits:
00000000000
10000000000
11000000000
11100000000
11110000000
11111000000
11111100000
11111110000
11111111000
11111111100
11111111110
11111111111