bit::matrix
— Transpose a Bit-Matrix
We supply a member function to transpose a square bit-matrix in place and a free function that transposes an arbitrary bit-matrix.
1constexpr bit::matrix &to_transpose();
template<std::unsigned_integral Block, typename Allocator>
constexpr matrix<Block, Allocator>
2(const matrix<Block, Allocator> &M); transpose
- 1
- Member function to transpose a square bit-matrix in place.
- 2
- Free function that returns the transpose of an arbitrary bit-matrix.
The transpose of a matrix \(M\) with elements \(M_{ij}\) is the matrix \(M^T\) whose elements are \[ M^T_{ij} = M_{ji} \]
Example
#include <bit/bit.h>
int main()
{
::matrix<> m(4, [](std::size_t i, std::size_t) { return (i + 1)%2; });
bitauto m1 = m;
std::cout << "Original and transposed matrices:\n";
::print(m, m1.to_transpose());
bit
::matrix<> m2(4, 8, [](std::size_t i, std::size_t) { return (i + 1)%2; });
bitstd::cout << "Original and transposed matrices:\n";
::print(m2, bit::transpose(m2));
bit}
Output
Original and transposed matrices:
1111 1010
0000 1010
1111 1010
0000 1010
Original and transposed matrices:
11111111 1010
00000000 1010
11111111 1010
00000000 1010
1010
1010
1010
1010