GF2::Matrix — Stream Operators
Methods to insert or extract a bit-matrix from a stream.
template<std::unsigned_integral Block, typename Allocator>
std::ostream &
operator<<(std::ostream &s, const Matrix<Block, Allocator> &M); (1)
template<std::unsigned_integral Block, typename Allocator>
std::istream &
operator>>(std::istream &s, Matrix<Block, Allocator> &M); (2)
| 1 | Writes a binary string representation of a bit-matrix to an output stream. |
| 2 | Fill a bit-matrix by reading bits encoded as a binary or hex string from a stream. |
The input stream operator will throw a std::invalid_argument exception on parse failures.
The bit-matrix is printed in rows separated by newlines.
Each row is printed as a GF2::Vector in vector-order so row \(i\) is in the order \(M_{i0}M_{i1}M_{i2}\cdots\).
The input stream operator can handle other row separators and also hex formatted strings.
Example
#include <GF2/GF2.h>
int main()
{
// Read from a stream until we have a parse error ...
while (true) {
GF2::Matrix<> m;
std::cout << "GF2::Matrix? ";
try {
std::cin >> m;
std::cout << "Parsed as:\n" << m << std::endl;
}
catch (...) {
std::cout << "Couldn't parse that input as a GF2::Matrix! Quitting ..." << std::endl;
break;
}
}
}
Input and Output
GF2::Matrix? 11111 10101 01010; 00100
Parsed as:
11111
10101
01010
00100
GF2::Matrix? 0xff 0xf2 0x3e 0x45
Parsed as:
11111111
11110100
11000111
00101010
GF2::Matrix? q
Couldn't parse that input as a GF2::Matrix! Quitting ...
See Also