From 18915b66100b3adb39858219a13c63e44f11376d Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 15 Aug 2016 17:42:09 +1000 Subject: [PATCH] matrix: use infix_iterator for ostream operator --- matrix.cpp | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/matrix.cpp b/matrix.cpp index 44e48d87..32ffeb24 100644 --- a/matrix.cpp +++ b/matrix.cpp @@ -16,8 +16,9 @@ #include "matrix.hpp" -#include "point.hpp" #include "debug.hpp" +#include "iterator.hpp" +#include "point.hpp" #include #include @@ -446,33 +447,23 @@ namespace util { } -//----------------------------------------------------------------------------- -namespace util { - template - std::ostream& - operator<< (std::ostream &os, const matrix &m) - { - os << "{ {" << m.values[0][0] << ", " - << m.values[0][1] << ", " - << m.values[0][2] << ", " - << m.values[0][3] << "}, " - << "{" << m.values[1][0] << ", " - << m.values[1][1] << ", " - << m.values[1][2] << ", " - << m.values[1][3] << "}, " - << "{" << m.values[2][0] << ", " - << m.values[2][1] << ", " - << m.values[2][2] << ", " - << m.values[2][3] << "}, " - << "{" << m.values[3][0] << ", " - << m.values[3][1] << ", " - << m.values[3][2] << ", " - << m.values[3][3] << "} }"; +/////////////////////////////////////////////////////////////////////////////// +template +std::ostream& +util::operator<< (std::ostream &os, const matrix &m) +{ + os << "{ "; - return os; + for (size_t i = 0; i < S; ++i) { + os << "{ "; + std::copy (m[i], m[i]+S, util::infix_iterator (os, ", ")); + os << ((i == S - 1) ? " }" : " }, "); } + + return os << " }"; } +//----------------------------------------------------------------------------- template std::ostream& util::operator<< (std::ostream&, const matrix<4,float>&); template std::ostream& util::operator<< (std::ostream&, const matrix<4,double>&);