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*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>
static const char *get_name() { return "Vector"; }
private:
+ void constructors();
void component_aliases();
void composition();
void slice();
VectorTests::VectorTests()
{
+ add(&VectorTests::constructors, "Constructors");
add(&VectorTests::component_aliases, "Component aliases");
add(&VectorTests::composition, "Compose");
add(&VectorTests::slice, "Slice");
add(&VectorTests::unit_vec, "Normalize");
}
+void VectorTests::constructors()
+{
+ static int data[] = { 1, 2, 3 };
+
+ Vector2i v1(1, 2);
+ EXPECT_EQUAL(v1[0], 1);
+ EXPECT_EQUAL(v1[1], 2);
+
+ Vector3i v2(data);
+ EXPECT_EQUAL(v2[0], 1);
+ EXPECT_EQUAL(v2[1], 2);
+ EXPECT_EQUAL(v2[2], 3);
+
+#if __cplusplus >= 201103L
+ LinAl::Vector<int, 1> v3(1);
+ EXPECT_EQUAL(v3[0], 1);
+
+ LinAl::Vector<int, 5> v4(1, 2, 3, 4, 5);
+ EXPECT_EQUAL(v4[0], 1);
+ EXPECT_EQUAL(v4[4], 5);
+#endif
+}
+
void VectorTests::component_aliases()
{
Vector3i v;