Vector(T, T, T, T);
template<typename U>
Vector(const Vector<U, N> &);
- template<typename U>
- Vector(const Vector<U, N-1> &, U);
- template<typename U>
- explicit Vector(const Vector<U, N+1> &);
+
+ template<unsigned M>
+ Vector<T, M> slice(unsigned) const;
Vector &operator*=(T);
Vector &operator/=(T);
}
template<typename T, unsigned N>
-template<typename U>
-inline Vector<T, N>::Vector(const Vector<U, N-1> &v, U s)
+inline Vector<T, N+1> compose(const Vector<T, N> &v, T s)
{
- for(unsigned i=0; i<N-1; ++i)
- (*this)[i] = v[i];
- (*this)[N-1] = s;
+ Vector<T, N+1> r;
+ for(unsigned i=0; i<N; ++i)
+ r[i] = v[i];
+ r[N] = s;
+ return r;
}
template<typename T, unsigned N>
-template<typename U>
-inline Vector<T, N>::Vector(const Vector<U, N+1> &v)
+inline Vector<T, N+1> compose(T s, const Vector<T, N> &v)
{
+ Vector<T, N+1> r;
for(unsigned i=0; i<N; ++i)
- (*this)[i] = v[i];
+ r[i] = v[i];
+ r[N] = s;
+ return r;
+}
+
+template<typename T, unsigned N, unsigned M>
+inline Vector<T, N+M> compose(const Vector<T, N> &v1, const Vector<T, M> &v2)
+{
+ Vector<T, N+M> r;
+ for(unsigned i=0; i<N; ++i)
+ r[i] = v1[i];
+ for(unsigned i=0; i<M; ++i)
+ r[N+i] = v2[i];
+ return r;
+}
+
+template<typename T, unsigned N>
+template<unsigned M>
+inline Vector<T, M> Vector<T, N>::slice(unsigned j) const
+{
+ Vector<T, M> r;
+ for(unsigned i=0; i<M; ++i)
+ r[i] = (*this)[j+i];
+ return r;
}
template<typename T, unsigned N>
template<typename T, unsigned N>
inline T Vector<T, N>::norm() const
{
+ using std::sqrt;
return sqrt(inner_product(*this, *this));
}