support for std::cout

This commit is contained in:
Thomas Gubler
2015-12-26 12:07:12 +01:00
parent 9cd6ac3dd9
commit d999923a35
2 changed files with 28 additions and 0 deletions
+21
View File
@@ -13,6 +13,10 @@
#include <stdlib.h>
#include <string.h>
#include <math.h>
#if defined(SUPPORT_STDIOSTREAM)
#include <iostream>
#include <iomanip>
#endif // defined(SUPPORT_STDIOSTREAM)
#include "math.hpp"
@@ -413,6 +417,23 @@ Matrix<Type, M, N> ones() {
return m;
}
#if defined(SUPPORT_STDIOSTREAM)
template<typename Type, size_t M, size_t N>
std::ostream& operator<<(std::ostream& os,
const matrix::Matrix<Type, M, N>& matrix)
{
for (size_t i = 0; i < M; ++i) {
os << "[";
for (size_t j = 0; j < N; ++j) {
os << std::setw(10) << static_cast<double>(matrix(i, j));
os << "\t";
}
os << "]" << std::endl;
}
return os;
}
#endif // defined(SUPPORT_STDIOSTREAM)
typedef Matrix<float, 3, 3> Matrix3f;
}; // namespace matrix