GF2::Matrix — Replace Some Content
Replaces some of the values in a bit-matrix with those of another.
constexpr Matrix &replace(std::size_t i0, std::size_t j0, const Matrix &with); (1)
constexpr Matrix &replace(std::size_t i0, const Matrix &with); (2)
constexpr Matrix &replace(const Matrix &with); (3)
| 1 | Starting at index pair (i0,j0) replace the bit-matrix values with those from the bit-matrix with. |
| 2 | Starting at index pair (i0,i0) replace the bit-matrix values with those from the bit-matrix with. |
| 3 | Starting at index pair (0,0) replace the bit-matrix values with those from the bit-matrix with. |
The sub-matrix with we are copying from must fit inside the existing bit-matrix!
If the GF2_DEBUG flag is set at compile time this is checked and any violation will cause the program to abort with a helpful message.
|
These methods return a reference to *this so can be chained with other calls.
Example
#include <GF2/GF2.h>
int main()
{
auto m = GF2::Matrix<>::ones(8); (1)
GF2::Matrix<> w(3); (2)
std::cout << "m:\n" << m << '\n';
m.replace(w); (3)
std::cout << "m:\n" << m << '\n';
m.replace(5,w); (4)
std::cout << "m:\n" << m << '\n';
m.replace(5,0,w); (5)
std::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:
11111111
11111111
11111111
11111111
11111111
11111111
11111111
11111111
m:
00011111
00011111
00011111
11111111
11111111
11111111
11111111
11111111
m:
00011111
00011111
00011111
11111111
11111111
11111000
11111000
11111000
m:
00011111
00011111
00011111
11111111
11111111
00011000
00011000
00011000
See Also