summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2019-02-23 11:53:09 +0100
committerNao Pross <naopross@thearcway.org>2019-02-23 11:53:09 +0100
commit43ee238b931dfaf5124d24e5cd8c09234a75212f (patch)
treecad65df005ab86919677c718339b5928130877ec
parentAdd +, -, * operators to mm::basic_matrix (diff)
downloadlibmm-43ee238b931dfaf5124d24e5cd8c09234a75212f.tar.gz
libmm-43ee238b931dfaf5124d24e5cd8c09234a75212f.zip
Add operator<< for basic_matrix
-rw-r--r--include/mmmatrix.hpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/include/mmmatrix.hpp b/include/mmmatrix.hpp
index 51233cb..7cb9359 100644
--- a/include/mmmatrix.hpp
+++ b/include/mmmatrix.hpp
@@ -11,8 +11,7 @@
*/
#pragma once
-#include <cmath>
-#include <array>
+#include <iostream>
namespace mm {
template<typename T, std::size_t Rows, std::size_t Cols>
@@ -191,3 +190,16 @@ mm::basic_matrix<T, Rows, Cols> operator-(
) {
return a + static_cast<T>(-1) * b;
}
+
+template<typename T, std::size_t Rows, std::size_t Cols>
+std::ostream& operator<<(std::ostream& os, const mm::basic_matrix<T, Rows, Cols>& m) {
+ for (int row = 0; row < Rows; row++) {
+ os << "[ ";
+ for (int col = 0; col < (Cols -1); col++) {
+ os << m.at(row, col);
+ }
+ os << m.at(Rows -1, Cols -1) << " ]\n";
+ }
+
+ return os;
+}