bit::matrix — Resize a Bit-Matrix

Resizes the bit-matrix, initializing any added elements to 0.

1constexpr bit::matrix &resize(std::size_t r, std::size_t c);
2constexpr bit::matrix &resize(std::size_t n);
1
Resize the bit-matrix to be r x c.
2
Resize the bit-matrix to be n x n.

If r < rows(), the bit-matrix is reduced in size to the first r rows.
If r > rows(), we append extra rows of zeros to the end of the bit-matrix.
If c < cols(), the bit-matrix is reduced in size to the first c columns.
If c > cols(), we append extra columns of zeros to the end of the bit-matrix.

This method returns a reference to *this so it can be chained with other calls.

Example

#include <bit/bit.h>
int main()
{
1    auto m = bit::matrix<>::random(4);
    std::cout << "m:\n" << m << '\n';
2    m.resize(6,8);
    std::cout << "m:\n" << m << '\n';
3    m.resize(4);
    std::cout << "m:\n" << m << '\n';
}
1
Construct a 4 x 4 bit-matrix with a random fill.
2
Resize the bit-matrix to have 6 x 8. The extra two rows and columns get initialized with zeros.
3
Resize the bit-matrix to the original 4 x 4 size.

Output

m:
│1 1 0 0│
│1 1 0 1│
│1 1 1 0│
│1 1 1 0│
m:
│1 1 0 0 0 0 0 0│
│1 1 0 1 0 0 0 0│
│1 1 1 0 0 0 0 0│
│1 1 1 0 0 0 0 0│
│0 0 0 0 0 0 0 0│
│0 0 0 0 0 0 0 0│
m:
│1 1 0 0│
│1 1 0 1│
│1 1 1 0│
│1 1 1 0│

See Also

matrix::clear
matrix::add_row
matrix::add_col
matrix::pop_row
matrix::pop_col

Back to top