X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flinal%2Fvector.h;h=610ac2103a21ab83e0b58f88905e6d07c6962d2d;hb=d0534789125d5ef8c44743b1fd9eaff21b9e7e0d;hp=c9b2a179fe5fd0ce595e4dda796b3c2d7b13ab5d;hpb=9ab061034720c1c0db4e8bff5dae4191ccd2a26f;p=libs%2Fmath.git diff --git a/source/linal/vector.h b/source/linal/vector.h index c9b2a17..610ac21 100644 --- a/source/linal/vector.h +++ b/source/linal/vector.h @@ -84,9 +84,9 @@ public: use by Matrix row accessor. */ Vector(const T *, unsigned); - Vector(T, T); - Vector(T, T, T); - Vector(T, T, T, T); + template + Vector(T, Args...); + template Vector(const Vector &); @@ -126,30 +126,15 @@ inline Vector::Vector(const T *d, unsigned stride) (*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 -inline Vector::Vector(T x_, T y_) -{ - this->VectorComponents::x = x_; - this->VectorComponents::y = y_; -} - -template -inline Vector::Vector(T x_, T y_, T z_) -{ - this->VectorComponents::x = x_; - this->VectorComponents::y = y_; - this->VectorComponents::z = z_; -} - template -inline Vector::Vector(T x_, T y_, T z_, T w_) -{ - this->VectorComponents::x = x_; - this->VectorComponents::y = y_; - this->VectorComponents::z = z_; - this->VectorComponents::w = w_; +template +inline Vector::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 { static_cast(v)... }) + (*this)[i++] = c; } template @@ -174,9 +159,9 @@ template inline Vector compose(T s, const Vector &v) { Vector r; + r[0] = s; for(unsigned i=0; i