#include <algorithm>
#include <cmath>
+#include <ostream>
namespace Msp {
namespace LinAl {
class Vector: public VectorComponents<T, N>
{
public:
+ typedef T ElementType;
+
Vector();
Vector(const T *);
+
+ /** Constructs a vector from an array of interleaved values. Intended for
+ use by Matrix row accessor. */
+ Vector(const T *, unsigned);
+
Vector(T, T);
Vector(T, T, T);
Vector(T, T, T, T);
template<typename U>
Vector(const Vector<U, N> &);
+ unsigned size() const { return N; }
+
template<unsigned M>
Vector<T, M> slice(unsigned) const;
(*this)[i] = d[i];
}
+template<typename T, unsigned N>
+inline Vector<T, N>::Vector(const T *d, unsigned stride)
+{
+ for(unsigned i=0; i<N; ++i)
+ (*this)[i] = d[i*stride];
+}
+
/* The compiler won't instantiate these unless they are used. Trying to use
them on the wrong class results in an error. */
template<typename T, unsigned N>
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