]> git.tdb.fi Git - libs/math.git/blobdiff - source/linal/vector.h
Add formatted output operators for vector and matrix classes
[libs/math.git] / source / linal / vector.h
index 9a9d02822aebe554627178803b4c6bd4c2621ddc..c9b2a179fe5fd0ce595e4dda796b3c2d7b13ab5d 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <algorithm>
 #include <cmath>
+#include <ostream>
 
 namespace Msp {
 namespace LinAl {
@@ -325,6 +326,20 @@ inline Vector<T, 3> cross(const Vector<T, 3> &v1, const Vector<T, 3> &v2)
        return Vector<T, 3>(v1.y*v2.z-v1.z*v2.y, v1.z*v2.x-v1.x*v2.z, v1.x*v2.y-v1.y*v2.x);
 }
 
+template<typename T, unsigned N>
+inline std::ostream &operator<<(std::ostream &s, const Vector<T, N> &v)
+{
+       s << "Vector" << N << '(';
+       for(unsigned i=0; i<N; ++i)
+       {
+               if(i)
+                       s << ", ";
+               s << v[i];
+       }
+       s << ')';
+       return s;
+}
+
 } // namespace LinAl
 } // namespace Msp