#include <algorithm>
#include <cmath>
+#include <ostream>
namespace Msp {
namespace LinAl {
Vector();
Vector(const T *);
+
+ /** Constructs a vector from an array of interleaved values. Intended for
+ use by Matrix row accessor. */
+ Vector(const T *, unsigned);
+
+#if __cplusplus >= 201103L
+ template<typename... Args>
+ Vector(T, Args...);
+#else
Vector(T, T);
Vector(T, T, T);
Vector(T, T, T, T);
+#endif
template<typename U>
Vector(const Vector<U, N> &);
(*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];
+}
+
+#if __cplusplus >= 201103L
+template<typename T, unsigned N>
+template<typename... Args>
+inline Vector<T, N>::Vector(T x_, Args... v)
+{
+ static_assert(1+sizeof...(v)==N, "Incorrect number of arguments in Vector constructor");
+ (*this)[0] = x_;
+ unsigned i = 1;
+ for(auto c: std::initializer_list<T> { static_cast<T>(v)... })
+ (*this)[i++] = c;
+}
+#else
/* 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>
this->VectorComponents<T, 4>::z = z_;
this->VectorComponents<T, 4>::w = w_;
}
+#endif
template<typename T, unsigned N>
template<typename U>
inline Vector<T, N+1> compose(T s, const Vector<T, N> &v)
{
Vector<T, N+1> r;
+ r[0] = s;
for(unsigned i=0; i<N; ++i)
- r[i] = v[i];
- r[N] = s;
+ r[i+1] = v[i];
return r;
}
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