bit::matrix
— Replace Some Content
We have methods that replace some of the values in a bit-matrix with those of another.
constexpr bit::matrix&
1(std::size_t i0, std::size_t j0, const bit::matrix &with);
replace
constexpr bit::matrix&
2(std::size_t i0, const bit::matrix &with);
replace
constexpr bit::matrix&
3(const bit::matrix &with); replace
- 1
-
Starting at index pair
(i0,j0)
, replace the bit-matrix values with those from the bit-matrixwith
. - 2
-
Starting at index pair
(i0,i0)
, replace the bit-matrix values with those from the bit-matrixwith
. - 3
-
Starting at index pair
(0,0)
, replace the bit-matrix values with those from the bit-matrixwith
.
The sub-matrix with we are copying from must fit inside the existing bit-matrix! Set the BIT_VERIFY flag at compile time to check this condition — any violation will cause the program to abort with a helpful message.
|
These methods return a reference to *this
so they can be chained with other calls.
Example
#include <bit/bit.h>
int main()
{
1auto m = bit::matrix<>::ones(8);
2::matrix<> w(3);
bitstd::cout << "m:\n" << m << '\n';
3.replace(w);
mstd::cout << "m:\n" << m << '\n';
4.replace(5,w);
mstd::cout << "m:\n" << m << '\n';
5.replace(5,0,w);
mstd::cout << "m:\n" << m << '\n';
}
- 1
-
Start with an 8 x 8 bit-matrix
m
that is all ones. - 2
-
The replacement values will always be that 3 x 3 bit-matrix
w
that is all zeros. - 3
-
Replaces 3 x 3 values in
m
starting at the upper left element(0,0)
. - 4
-
Replaces 3 x 3 values in
m
starting at the element(5,5)
. - 5
-
Replaces 3 x 3 values in
m
starting at the element(5,0)
.
Output
m:
│1 1 1 1 1 1 1 1│
│1 1 1 1 1 1 1 1│
│1 1 1 1 1 1 1 1│
│1 1 1 1 1 1 1 1│
│1 1 1 1 1 1 1 1│
│1 1 1 1 1 1 1 1│
│1 1 1 1 1 1 1 1│
│1 1 1 1 1 1 1 1│
m:
│0 0 0 1 1 1 1 1│
│0 0 0 1 1 1 1 1│
│0 0 0 1 1 1 1 1│
│1 1 1 1 1 1 1 1│
│1 1 1 1 1 1 1 1│
│1 1 1 1 1 1 1 1│
│1 1 1 1 1 1 1 1│
│1 1 1 1 1 1 1 1│
m:
│0 0 0 1 1 1 1 1│
│0 0 0 1 1 1 1 1│
│0 0 0 1 1 1 1 1│
│1 1 1 1 1 1 1 1│
│1 1 1 1 1 1 1 1│
│1 1 1 1 1 0 0 0│
│1 1 1 1 1 0 0 0│
│1 1 1 1 1 0 0 0│
m:
│0 0 0 1 1 1 1 1│
│0 0 0 1 1 1 1 1│
│0 0 0 1 1 1 1 1│
│1 1 1 1 1 1 1 1│
│1 1 1 1 1 1 1 1│
│0 0 0 1 1 0 0 0│
│0 0 0 1 1 0 0 0│
│0 0 0 1 1 0 0 0│