bit::matrix — Add & Remove Rows/Columns

We have methods to add and remove rows & columns from the end of the bit-matrix.

1constexpr bit::matrix &add_row();
2constexpr bit::matrix &add_col();
3constexpr bit::matrix &pop_row();
4constexpr bit::matrix &pop_col();
1
Add a new row of zeros to the end of the bit-matrix.
2
Add a new column of zeros to the end of the bit-matrix.
3
Remove the last row from the bit-matrix.
4
Remove the last columns from the bit-matrix.

These methods all return a reference to *this so they can be chained with other calls.

Example

#include <bit/bit.h>
int main()
{
    auto m = bit::matrix<>::ones(2,8);
    std::cout << "m:\n" << m << '\n';
    m.add_row();
    std::cout << "m:\n" << m << '\n';
    m.add_col();
    std::cout << "m:\n" << m << '\n';
    m.pop_row();
    std::cout << "m:\n" << m << '\n';
    m.pop_col();
    std::cout << "m:\n" << m << '\n';
1    m.clear();
    std::cout << "m:\n" << m << '\n';
2    m.add_row();
    std::cout << "m:\n" << m << '\n';
3    m.pop_col();
    std::cout << "m:\n" << m << '\n';
}
1
Clears the bit-matrix.
2
Adding a row or a column to an empty bit-matrix does nothing.
3
Popping a row or a column from an empty bit-matrix does nothing.

Output

m:
│1 1 1 1 1 1 1 1│
│1 1 1 1 1 1 1 1│
m:
│1 1 1 1 1 1 1 1│
│1 1 1 1 1 1 1 1│
│0 0 0 0 0 0 0 0│
m:
│1 1 1 1 1 1 1 1 0│
│1 1 1 1 1 1 1 1 0│
│0 0 0 0 0 0 0 0 0│
m:
│1 1 1 1 1 1 1 1 0│
│1 1 1 1 1 1 1 1 0│
m:
│1 1 1 1 1 1 1 1│
│1 1 1 1 1 1 1 1│
m:
[]
m:
[]
m:
[]

See Also

matrix::resize
matrix::clear

Back to top