diff --git a/CMakeLists.txt b/CMakeLists.txt index 639f9b19e2..19cb107e5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/matrix/Matrix.hpp b/matrix/Matrix.hpp index 2e32fc29b2..8d85946ed6 100644 --- a/matrix/Matrix.hpp +++ b/matrix/Matrix.hpp @@ -13,6 +13,10 @@ #include #include #include +#if defined(SUPPORT_STDIOSTREAM) +#include +#include +#endif // defined(SUPPORT_STDIOSTREAM) #include "math.hpp" @@ -413,6 +417,23 @@ Matrix ones() { return m; } +#if defined(SUPPORT_STDIOSTREAM) +template +std::ostream& operator<<(std::ostream& os, + const matrix::Matrix& matrix) +{ + for (size_t i = 0; i < M; ++i) { + os << "["; + for (size_t j = 0; j < N; ++j) { + os << std::setw(10) << static_cast(matrix(i, j)); + os << "\t"; + } + os << "]" << std::endl; + } + return os; +} +#endif // defined(SUPPORT_STDIOSTREAM) + typedef Matrix Matrix3f; }; // namespace matrix