bit::matrix — Element Access
We have methods to access the rows, the columns, and the individual elements/bits in a bit-matrix.
constexpr bool
1operator()(std::size_t i, std::size_t j);
constexpr bool
2test(std::size_t i, std::size_t j) const;
constexpr bit::vector::reference
3operator()(std::size_t i, std::size_t j);
constexpr const bit::vector&
4row(std::size_t i) const;
constexpr bit::vector&
row(std::size_t i);
constexpr const bit::vector&
5operator[](std::size_t i) const;
constexpr bit::vector&
operator[](std::size_t i);
constexpr bit::vector
6col(std::size_t j) const;- 1
-
Accesses the element at
(i, j). - 2
-
Another way to access element
(i, j). - 3
-
Returns an object of type
vector::referencethat lets you write to slot(i, j). - 4
-
Read-only & read-write access to the elements in row
iof a bit-matrix. - 5
-
Synonyms for the
row(i)methods to allow for alternateCstyle indexing a lamatrix[i][j]. - 6
-
Read-only access to the elements in column
iof a bit-matrix.
In general, these methods do not check whether an index is in bounds, and if it isn’t, the behaviour is undefined (but bound to be wrong!) Set the BIT_VERIFY flag at compile time to check this condition — any violation will cause the program to abort with a helpful message.
|
Example
#include <bit/bit.h>
int main()
{
std::size_t n = 4;
auto mat = bit::matrix<>::random(n);
std::cout << "bit::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
bit::matrix:
│0 1 1 0│
│0 1 0 0│
│0 1 1 0│
│0 1 0 0│
By rows ...
Row 0: [0 1 1 0]
Row 1: [0 1 0 0]
Row 2: [0 1 1 0]
Row 3: [0 1 0 0]
By columns ...
Col 0: [0 0 0 0]
Col 1: [1 1 1 1]
Col 2: [1 0 1 0]