GF2::Matrix — Element Access

Methods to access the rows, the columns, and the individual elements/bits in a bit-matrix.

constexpr bool operator()(std::size_t i, std::size_t j);                    (1)
constexpr GF2::Vector::reference operator()(std::size_t i, std::size_t j);  (2)
constexpr const vector_type &row(std::size_t i) const;                      (3)
constexpr vector_type &row(std::size_t i);
constexpr const vector_type &operator[](std::size_t i) const;               (4)
constexpr vector_type &operator[](std::size_t i);
constexpr vector_type col(std::size_t j) const;                             (5)
constexpr bool test(std::size_t i, std::size_t j) const;                    (6)
1 Accesses the value for the bit-matrix element (i, j).
2 Returns an object of type GF2::Vector::reference that allows the modification of the value at (i, j).
3 Read-only & read-write access to the elements in row i of a bit-matrix.
4 Synonyms for the row(i) methods to allow for alternate “C” style indexing a la matrix[i][j].
5 Read-only access to the elements in column i of a bit-matrix. Returns a distinct bit-vector.
6 Another way to access the value for element (i, j).
In general, these methods do not check whether an index is in bounds and if it isn’t the behavior is undefined (but bound 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 = 4;
    auto mat = GF2::Matrix<>::random(n);
    std::cout << "Matrix:\n";
    std::cout << mat << '\n';
    std::cout << "By rows ...\n";
    for (std::size_t i = 0; i < n; ++i)
        std::cout << "Row " << i << ": " << mat[i] << '\n';
    std::cout << "By columns ...\n";
    for (std::size_t i = 0; i < n; ++i)
        std::cout << "Col " << i << ": " << mat.col(i) << '\n';
}
Output
Matrix:
0101
0100
1010
1101
By rows ...
Row 0: 0101
Row 1: 0100
Row 2: 1010
Row 3: 1101
By columns ...
Col 0: 0011
Col 1: 1101
Col 2: 0010
Col 3: 1001