Added assert for initilizer lists to match sizes

This commit is contained in:
Christophe Riccio 2013-10-05 21:03:53 +02:00
parent eb59cb9af6
commit 4acd5b087d
11 changed files with 86 additions and 68 deletions

View File

@ -144,21 +144,23 @@ namespace detail
#if(GLM_HAS_INITIALIZER_LISTS) #if(GLM_HAS_INITIALIZER_LISTS)
template <typename T, precision P> template <typename T, precision P>
template <typename U> template <typename U>
GLM_FUNC_QUALIFIER tmat2x2<T, P>::tmat2x2(std::initializer_list<U> m) GLM_FUNC_QUALIFIER tmat2x2<T, P>::tmat2x2(std::initializer_list<U> l)
{ {
assert(m.size() >= this->length()); assert(l.size() == this->length() * this->value[0].length());
typename std::initializer_list<U>::iterator p = m.begin(); typename std::initializer_list<U>::iterator p = l.begin();
this->value[0] = tvec2<T, P>(*(p + 0), *(p + 1)); this->value[0] = tvec2<T, P>(*(p + 0), *(p + 1));
this->value[1] = tvec2<T, P>(*(p + 2), *(p + 3)); this->value[1] = tvec2<T, P>(*(p + 2), *(p + 3));
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat2x2<T, P>::tmat2x2(std::initializer_list<tvec2<T, P> > m) GLM_FUNC_QUALIFIER tmat2x2<T, P>::tmat2x2(std::initializer_list<tvec2<T, P> > l)
{ {
this->value[0] = m.begin()[0]; assert(l.size() == this->length());
this->value[1] = m.begin()[1];
this->value[0] = l.begin()[0];
this->value[1] = l.begin()[1];
} }
#endif//GLM_HAS_INITIALIZER_LISTS #endif//GLM_HAS_INITIALIZER_LISTS

View File

@ -143,21 +143,23 @@ namespace detail
#if(GLM_HAS_INITIALIZER_LISTS) #if(GLM_HAS_INITIALIZER_LISTS)
template <typename T, precision P> template <typename T, precision P>
template <typename U> template <typename U>
GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3(std::initializer_list<U> m) GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3(std::initializer_list<U> l)
{ {
assert(m.size() >= this->length()); assert(l.size() == this->length() * this->value[0].length());
typename std::initializer_list<U>::iterator p = m.begin(); typename std::initializer_list<U>::iterator p = l.begin();
this->value[0] = tvec3<T, P>(*(p + 0), *(p + 1), *(p + 2)); this->value[0] = tvec3<T, P>(*(p + 0), *(p + 1), *(p + 2));
this->value[1] = tvec3<T, P>(*(p + 3), *(p + 4), *(p + 5)); this->value[1] = tvec3<T, P>(*(p + 3), *(p + 4), *(p + 5));
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3(std::initializer_list<tvec3<T, P> > m) GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3(std::initializer_list<tvec3<T, P> > l)
{ {
this->value[0] = m.begin()[0]; assert(l.size() == this->length());
this->value[1] = m.begin()[1];
this->value[0] = l.begin()[0];
this->value[1] = l.begin()[1];
} }
#endif//GLM_HAS_INITIALIZER_LISTS #endif//GLM_HAS_INITIALIZER_LISTS

View File

@ -146,21 +146,23 @@ namespace detail
#if(GLM_HAS_INITIALIZER_LISTS) #if(GLM_HAS_INITIALIZER_LISTS)
template <typename T, precision P> template <typename T, precision P>
template <typename U> template <typename U>
GLM_FUNC_QUALIFIER tmat2x4<T, P>::tmat2x4(std::initializer_list<U> m) GLM_FUNC_QUALIFIER tmat2x4<T, P>::tmat2x4(std::initializer_list<U> l)
{ {
assert(m.size() >= this->length()); assert(l.size() == this->length() * this->value[0].length());
typename std::initializer_list<U>::iterator p = m.begin(); typename std::initializer_list<U>::iterator p = l.begin();
this->value[0] = tvec4<T, P>(*(p + 0), *(p + 1), *(p + 2), *(p + 3)); this->value[0] = tvec4<T, P>(*(p + 0), *(p + 1), *(p + 2), *(p + 3));
this->value[1] = tvec4<T, P>(*(p + 4), *(p + 5), *(p + 6), *(p + 7)); this->value[1] = tvec4<T, P>(*(p + 4), *(p + 5), *(p + 6), *(p + 7));
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat2x4<T, P>::tmat2x4(std::initializer_list<tvec4<T, P> > m) GLM_FUNC_QUALIFIER tmat2x4<T, P>::tmat2x4(std::initializer_list<tvec4<T, P> > l)
{ {
this->value[0] = m.begin()[0]; assert(l.size() == this->length());
this->value[1] = m.begin()[1];
this->value[0] = l.begin()[0];
this->value[1] = l.begin()[1];
} }
#endif//GLM_HAS_INITIALIZER_LISTS #endif//GLM_HAS_INITIALIZER_LISTS

View File

@ -80,9 +80,9 @@ namespace detail
#if(GLM_HAS_INITIALIZER_LISTS) #if(GLM_HAS_INITIALIZER_LISTS)
template <typename U> template <typename U>
GLM_FUNC_DECL tmat3x2(std::initializer_list<U> m); GLM_FUNC_DECL tmat3x2(std::initializer_list<U> l);
GLM_FUNC_DECL tmat3x2(std::initializer_list<tvec2<T, P> > m); GLM_FUNC_DECL tmat3x2(std::initializer_list<tvec2<T, P> > l);
#endif//GLM_HAS_INITIALIZER_LISTS #endif//GLM_HAS_INITIALIZER_LISTS
////////////////////////////////////// //////////////////////////////////////

View File

@ -151,11 +151,11 @@ namespace detail
#if(GLM_HAS_INITIALIZER_LISTS) #if(GLM_HAS_INITIALIZER_LISTS)
template <typename T, precision P> template <typename T, precision P>
template <typename U> template <typename U>
GLM_FUNC_QUALIFIER tmat3x2<T, P>::tmat3x2(std::initializer_list<U> m) GLM_FUNC_QUALIFIER tmat3x2<T, P>::tmat3x2(std::initializer_list<U> l)
{ {
assert(m.size() >= this->length()); assert(l.size() == this->length() * this->value[0].length());
typename std::initializer_list<U>::iterator p = m.begin(); typename std::initializer_list<U>::iterator p = l.begin();
this->value[0] = tvec2<T, P>(*(p + 0), *(p + 1)); this->value[0] = tvec2<T, P>(*(p + 0), *(p + 1));
this->value[1] = tvec2<T, P>(*(p + 2), *(p + 3)); this->value[1] = tvec2<T, P>(*(p + 2), *(p + 3));
@ -163,11 +163,13 @@ namespace detail
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat3x2<T, P>::tmat3x2(std::initializer_list<tvec2<T, P> > m) GLM_FUNC_QUALIFIER tmat3x2<T, P>::tmat3x2(std::initializer_list<tvec2<T, P> > l)
{ {
this->value[0] = m.begin()[0]; assert(l.size() == this->length());
this->value[1] = m.begin()[1];
this->value[2] = m.begin()[2]; this->value[0] = l.begin()[0];
this->value[1] = l.begin()[1];
this->value[2] = l.begin()[2];
} }
#endif//GLM_HAS_INITIALIZER_LISTS #endif//GLM_HAS_INITIALIZER_LISTS

View File

@ -154,11 +154,11 @@ namespace detail
#if(GLM_HAS_INITIALIZER_LISTS) #if(GLM_HAS_INITIALIZER_LISTS)
template <typename T, precision P> template <typename T, precision P>
template <typename U> template <typename U>
GLM_FUNC_QUALIFIER tmat3x3<T, P>::tmat3x3(std::initializer_list<U> m) GLM_FUNC_QUALIFIER tmat3x3<T, P>::tmat3x3(std::initializer_list<U> l)
{ {
assert(m.size() >= this->length()); assert(l.size() == this->length() * this->value[0].length());
typename std::initializer_list<U>::iterator p = m.begin(); typename std::initializer_list<U>::iterator p = l.begin();
this->value[0] = tvec3<T, P>(*(p + 0), *(p + 1), *(p + 2)); this->value[0] = tvec3<T, P>(*(p + 0), *(p + 1), *(p + 2));
this->value[1] = tvec3<T, P>(*(p + 3), *(p + 4), *(p + 5)); this->value[1] = tvec3<T, P>(*(p + 3), *(p + 4), *(p + 5));
@ -166,11 +166,13 @@ namespace detail
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat3x3<T, P>::tmat3x3(std::initializer_list<tvec3<T, P> > m) GLM_FUNC_QUALIFIER tmat3x3<T, P>::tmat3x3(std::initializer_list<tvec3<T, P> > l)
{ {
this->value[0] = m.begin()[0]; assert(l.size() == this->length());
this->value[1] = m.begin()[1];
this->value[2] = m.begin()[2]; this->value[0] = l.begin()[0];
this->value[1] = l.begin()[1];
this->value[2] = l.begin()[2];
} }
#endif//GLM_HAS_INITIALIZER_LISTS #endif//GLM_HAS_INITIALIZER_LISTS

View File

@ -198,11 +198,11 @@ namespace detail
#if(GLM_HAS_INITIALIZER_LISTS) #if(GLM_HAS_INITIALIZER_LISTS)
template <typename T, precision P> template <typename T, precision P>
template <typename U> template <typename U>
GLM_FUNC_QUALIFIER tmat3x4<T, P>::tmat3x4(std::initializer_list<U> m) GLM_FUNC_QUALIFIER tmat3x4<T, P>::tmat3x4(std::initializer_list<U> l)
{ {
assert(m.size() >= this->length()); assert(l.size() == this->length() * this->value[0].length());
typename std::initializer_list<U>::iterator p = m.begin(); typename std::initializer_list<U>::iterator p = l.begin();
this->value[0] = tvec4<T, P>(*(p + 0), *(p + 1), *(p + 2), *(p + 3)); this->value[0] = tvec4<T, P>(*(p + 0), *(p + 1), *(p + 2), *(p + 3));
this->value[1] = tvec4<T, P>(*(p + 4), *(p + 5), *(p + 6), *(p + 7)); this->value[1] = tvec4<T, P>(*(p + 4), *(p + 5), *(p + 6), *(p + 7));
@ -210,11 +210,13 @@ namespace detail
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat3x4<T, P>::tmat3x4(std::initializer_list<tvec4<T, P> > m) GLM_FUNC_QUALIFIER tmat3x4<T, P>::tmat3x4(std::initializer_list<tvec4<T, P> > l)
{ {
this->value[0] = m.begin()[0]; assert(l.size() == this->length());
this->value[1] = m.begin()[1];
this->value[2] = m.begin()[2]; this->value[0] = l.begin()[0];
this->value[1] = l.begin()[1];
this->value[2] = l.begin()[2];
} }
#endif//GLM_HAS_INITIALIZER_LISTS #endif//GLM_HAS_INITIALIZER_LISTS

View File

@ -209,11 +209,11 @@ namespace detail
#if(GLM_HAS_INITIALIZER_LISTS) #if(GLM_HAS_INITIALIZER_LISTS)
template <typename T, precision P> template <typename T, precision P>
template <typename U> template <typename U>
GLM_FUNC_QUALIFIER tmat4x2<T, P>::tmat4x2(std::initializer_list<U> m) GLM_FUNC_QUALIFIER tmat4x2<T, P>::tmat4x2(std::initializer_list<U> l)
{ {
assert(m.size() >= this->length()); assert(l.size() == this->length() * this->value[0].length());
typename std::initializer_list<U>::iterator p = m.begin(); typename std::initializer_list<U>::iterator p = l.begin();
this->value[0] = tvec2<T, P>(*(p + 0), *(p + 1)); this->value[0] = tvec2<T, P>(*(p + 0), *(p + 1));
this->value[1] = tvec2<T, P>(*(p + 2), *(p + 3)); this->value[1] = tvec2<T, P>(*(p + 2), *(p + 3));
@ -222,12 +222,14 @@ namespace detail
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x2<T, P>::tmat4x2(std::initializer_list<tvec2<T, P> > m) GLM_FUNC_QUALIFIER tmat4x2<T, P>::tmat4x2(std::initializer_list<tvec2<T, P> > l)
{ {
this->value[0] = m.begin()[0]; assert(l.size() == this->length());
this->value[1] = m.begin()[1];
this->value[2] = m.begin()[2]; this->value[0] = l.begin()[0];
this->value[3] = m.begin()[3]; this->value[1] = l.begin()[1];
this->value[2] = l.begin()[2];
this->value[3] = l.begin()[3];
} }
#endif//GLM_HAS_INITIALIZER_LISTS #endif//GLM_HAS_INITIALIZER_LISTS

View File

@ -155,11 +155,11 @@ namespace detail
#if(GLM_HAS_INITIALIZER_LISTS) #if(GLM_HAS_INITIALIZER_LISTS)
template <typename T, precision P> template <typename T, precision P>
template <typename U> template <typename U>
GLM_FUNC_QUALIFIER tmat4x3<T, P>::tmat4x3(std::initializer_list<U> m) GLM_FUNC_QUALIFIER tmat4x3<T, P>::tmat4x3(std::initializer_list<U> l)
{ {
assert(m.size() >= this->length()); assert(l.size() == this->length() * this->value[0].length());
typename std::initializer_list<U>::iterator p = m.begin(); typename std::initializer_list<U>::iterator p = l.begin();
this->value[0] = tvec3<T, P>(*(p + 0), *(p + 1), *(p + 2)); this->value[0] = tvec3<T, P>(*(p + 0), *(p + 1), *(p + 2));
this->value[1] = tvec3<T, P>(*(p + 3), *(p + 4), *(p + 5)); this->value[1] = tvec3<T, P>(*(p + 3), *(p + 4), *(p + 5));
@ -168,12 +168,14 @@ namespace detail
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x3<T, P>::tmat4x3(std::initializer_list<tvec3<T, P> > m) GLM_FUNC_QUALIFIER tmat4x3<T, P>::tmat4x3(std::initializer_list<tvec3<T, P> > l)
{ {
this->value[0] = m.begin()[0]; assert(l.size() == this->length());
this->value[1] = m.begin()[1];
this->value[2] = m.begin()[2]; this->value[0] = l.begin()[0];
this->value[3] = m.begin()[3]; this->value[1] = l.begin()[1];
this->value[2] = l.begin()[2];
this->value[3] = l.begin()[3];
} }
#endif//GLM_HAS_INITIALIZER_LISTS #endif//GLM_HAS_INITIALIZER_LISTS

View File

@ -177,11 +177,11 @@ namespace detail
#if(GLM_HAS_INITIALIZER_LISTS) #if(GLM_HAS_INITIALIZER_LISTS)
template <typename T, precision P> template <typename T, precision P>
template <typename U> template <typename U>
GLM_FUNC_QUALIFIER tmat4x4<T, P>::tmat4x4(std::initializer_list<U> m) GLM_FUNC_QUALIFIER tmat4x4<T, P>::tmat4x4(std::initializer_list<U> l)
{ {
assert(m.size() >= this->length()); assert(l.size() == this->length() * this->value[0].length());
typename std::initializer_list<U>::iterator p = m.begin(); typename std::initializer_list<U>::iterator p = l.begin();
this->value[0] = tvec4<T, P>(*(p + 0), *(p + 1), *(p + 2), *(p + 3)); this->value[0] = tvec4<T, P>(*(p + 0), *(p + 1), *(p + 2), *(p + 3));
this->value[1] = tvec4<T, P>(*(p + 4), *(p + 5), *(p + 6), *(p + 7)); this->value[1] = tvec4<T, P>(*(p + 4), *(p + 5), *(p + 6), *(p + 7));
@ -190,12 +190,14 @@ namespace detail
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P>::tmat4x4(std::initializer_list<tvec4<T, P> > m) GLM_FUNC_QUALIFIER tmat4x4<T, P>::tmat4x4(std::initializer_list<tvec4<T, P> > l)
{ {
this->value[0] = m.begin()[0]; assert(l.size() == this->length());
this->value[1] = m.begin()[1];
this->value[2] = m.begin()[2]; this->value[0] = l.begin()[0];
this->value[3] = m.begin()[3]; this->value[1] = l.begin()[1];
this->value[2] = l.begin()[2];
this->value[3] = l.begin()[3];
} }
#endif//GLM_HAS_INITIALIZER_LISTS #endif//GLM_HAS_INITIALIZER_LISTS

View File

@ -54,8 +54,8 @@ int test_ctr()
Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1; Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1;
std::vector<glm::mat3x2> v1{ std::vector<glm::mat3x2> v1{
{0, 1, 2, 3, 4, 5, 6, 7, 8}, {0, 1, 2, 3, 4, 5},
{0, 1, 2, 3, 4, 5, 6, 7, 8} {0, 1, 2, 3, 4, 5}
}; };
std::vector<glm::mat3x2> v2{ std::vector<glm::mat3x2> v2{