matrix: use vector ostream operator

This commit is contained in:
Danny Robson 2017-11-24 17:19:04 +11:00
parent a0b0863d61
commit c1036d8337
2 changed files with 14 additions and 26 deletions

View File

@ -342,24 +342,3 @@ util::to_euler (const matrix<Rows,Cols,T> &m)
template util::vector<3,float> util::to_euler (const matrix<3,3,float>&);
template util::vector<3,float> util::to_euler (const matrix<4,4,float>&);
///////////////////////////////////////////////////////////////////////////////
template <std::size_t Rows, std::size_t Cols, typename T>
std::ostream&
util::operator<< (std::ostream &os, const matrix<Rows,Cols,T> &m)
{
os << "{ ";
for (std::size_t i = 0; i < Rows; ++i) {
os << "{ ";
std::copy (std::cbegin (m[i]), std::cend (m[i]), util::infix_iterator<float> (os, ", "));
os << ((i == Rows - 1) ? " }" : " }, ");
}
return os << " }";
}
//-----------------------------------------------------------------------------
template std::ostream& util::operator<< (std::ostream&, const matrix<4,4,float>&);
template std::ostream& util::operator<< (std::ostream&, const matrix<4,4,double>&);

View File

@ -20,9 +20,10 @@
#include "point.hpp"
#include "range.hpp"
#include "vector.hpp"
#include "iterator.hpp"
#include <ostream>
#include <cstdlib>
#include <ostream>
namespace util {
template <
@ -469,9 +470,17 @@ namespace util {
///////////////////////////////////////////////////////////////////////////
template <std::size_t Rows, std::size_t Cols, typename T>
std::ostream& operator<< (std::ostream&, const matrix<Rows,Cols,T>&);
}
std::ostream&
operator<< (std::ostream &os, const matrix<Rows,Cols,T> &m)
{
os << '[';
std::copy (
std::cbegin (m),
std::cend (m),
util::infix_iterator<decltype(m[0])> (os, ", ")
);
return os << ']';
}
};
#endif