support for std::cout

This commit is contained in:
Thomas Gubler 2015-12-18 13:23:19 +01:00
parent 9cd6ac3dd9
commit d999923a35
2 changed files with 28 additions and 0 deletions

View File

@ -13,6 +13,13 @@ endif()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
STRINGS "Debug;Release;RelWithDebInfo;MinSizeRel;Profile")
option (SUPPORT_STDIOSTREAM
"If enabled provides support for << operator (as used with
std::cout)" OFF)
if((SUPPORT_STDIOSTREAM))
add_definitions(-DSUPPORT_STDIOSTREAM)
endif()
set(CMAKE_CXX_FLAGS_PROFILE
${CMAKE_CXX_FLAGS_DEBUG}
--coverage

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