Browse Source

Use initializer lists constructors for mat2

Christophe Riccio 7 years ago
parent
commit
3308b75836
2 changed files with 108 additions and 32 deletions
  1. 2 1
      glm/detail/setup.hpp
  2. 106 31
      glm/detail/type_mat2x2.inl

+ 2 - 1
glm/detail/setup.hpp

@@ -324,7 +324,7 @@
 		((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (GLM_COMPILER & GLM_COMPILER_CLANG)))
 #endif
 
-// N2672
+// N2672 Initializer lists http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2672.htm
 #if GLM_COMPILER & GLM_COMPILER_CLANG
 #	define GLM_HAS_INITIALIZER_LISTS __has_feature(cxx_generalized_initializers)
 #elif GLM_LANG & GLM_LANG_CXX11_FLAG
@@ -333,6 +333,7 @@
 #	define GLM_HAS_INITIALIZER_LISTS ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (\
 		((GLM_COMPILER & GLM_COMPILER_GCC)) || \
 		((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC12)) || \
+		((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_COMPILER >= GLM_COMPILER_INTEL14)) || \
 		((GLM_COMPILER & GLM_COMPILER_CUDA) && (GLM_COMPILER >= GLM_COMPILER_CUDA75))))
 #endif
 

+ 106 - 31
glm/detail/type_mat2x2.inl

@@ -30,16 +30,26 @@ namespace glm
 	template<typename T, qualifier Q>
 	template<qualifier P>
 	GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 2, T, Q>::mat(mat<2, 2, T, P> const& m)
+#		if GLM_HAS_INITIALIZER_LISTS
+			: value{m.value[0], m.value[1]}
+#		endif
 	{
-		this->value[0] = m.value[0];
-		this->value[1] = m.value[1];
+#		if !GLM_HAS_INITIALIZER_LISTS
+			this->value[0] = m.value[0];
+			this->value[1] = m.value[1];
+#		endif
 	}
 
 	template<typename T, qualifier Q>
 	GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 2, T, Q>::mat(T scalar)
+#		if GLM_HAS_INITIALIZER_LISTS
+			: value{col_type(scalar, 0), col_type(0, scalar)}
+#		endif
 	{
-		this->value[0] = col_type(scalar, 0);
-		this->value[1] = col_type(0, scalar);
+#		if !GLM_HAS_INITIALIZER_LISTS
+			this->value[0] = col_type(scalar, 0);
+			this->value[1] = col_type(0, scalar);
+#		endif
 	}
 
 	template<typename T, qualifier Q>
@@ -48,16 +58,26 @@ namespace glm
 		T const& x0, T const& y0,
 		T const& x1, T const& y1
 	)
+#		if GLM_HAS_INITIALIZER_LISTS
+			: value{col_type(x0, y0), col_type(x1, y1)}
+#		endif
 	{
-		this->value[0] = col_type(x0, y0);
-		this->value[1] = col_type(x1, y1);
+#		if !GLM_HAS_INITIALIZER_LISTS
+			this->value[0] = col_type(x0, y0);
+			this->value[1] = col_type(x1, y1);
+#		endif
 	}
 
 	template<typename T, qualifier Q>
 	GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 2, T, Q>::mat(col_type const& v0, col_type const& v1)
+#		if GLM_HAS_INITIALIZER_LISTS
+			: value{v0, v1}
+#		endif
 	{
-		this->value[0] = v0;
-		this->value[1] = v1;
+#		if !GLM_HAS_INITIALIZER_LISTS
+			this->value[0] = v0;
+			this->value[1] = v1;
+#		endif
 	}
 
 	// -- Conversion constructors --
@@ -69,17 +89,27 @@ namespace glm
 		X1 const& x1, Y1 const& y1,
 		X2 const& x2, Y2 const& y2
 	)
+#		if GLM_HAS_INITIALIZER_LISTS
+			: value{col_type(static_cast<T>(x1), value_type(y1)), col_type(static_cast<T>(x2), value_type(y2)) }
+#		endif
 	{
-		this->value[0] = col_type(static_cast<T>(x1), value_type(y1));
-		this->value[1] = col_type(static_cast<T>(x2), value_type(y2));
+#		if !GLM_HAS_INITIALIZER_LISTS
+			this->value[0] = col_type(static_cast<T>(x1), value_type(y1));
+			this->value[1] = col_type(static_cast<T>(x2), value_type(y2));
+#		endif
 	}
 
 	template<typename T, qualifier Q>
 	template<typename V1, typename V2>
 	GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 2, T, Q>::mat(vec<2, V1, Q> const& v1, vec<2, V2, Q> const& v2)
+#		if GLM_HAS_INITIALIZER_LISTS
+			: value{col_type(v1), col_type(v2)}
+#		endif
 	{
-		this->value[0] = col_type(v1);
-		this->value[1] = col_type(v2);
+#		if !GLM_HAS_INITIALIZER_LISTS
+			this->value[0] = col_type(v1);
+			this->value[1] = col_type(v2);
+#		endif
 	}
 
 	// -- mat2x2 matrix conversions --
@@ -87,65 +117,110 @@ namespace glm
 	template<typename T, qualifier Q>
 	template<typename U, qualifier P>
 	GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 2, T, Q>::mat(mat<2, 2, U, P> const& m)
+#		if GLM_HAS_INITIALIZER_LISTS
+			: value{col_type(m[0]), col_type(m[1])}
+#		endif
 	{
-		this->value[0] = col_type(m[0]);
-		this->value[1] = col_type(m[1]);
+#		if !GLM_HAS_INITIALIZER_LISTS
+			this->value[0] = col_type(m[0]);
+			this->value[1] = col_type(m[1]);
+#		endif
 	}
 
 	template<typename T, qualifier Q>
 	GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 2, T, Q>::mat(mat<3, 3, T, Q> const& m)
+#		if GLM_HAS_INITIALIZER_LISTS
+			: value{col_type(m[0]), col_type(m[1])}
+#		endif
 	{
-		this->value[0] = col_type(m[0]);
-		this->value[1] = col_type(m[1]);
+#		if !GLM_HAS_INITIALIZER_LISTS
+			this->value[0] = col_type(m[0]);
+			this->value[1] = col_type(m[1]);
+#		endif
 	}
 
 	template<typename T, qualifier Q>
 	GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 2, T, Q>::mat(mat<4, 4, T, Q> const& m)
+#		if GLM_HAS_INITIALIZER_LISTS
+			: value{col_type(m[0]), col_type(m[1])}
+#		endif
 	{
-		this->value[0] = col_type(m[0]);
-		this->value[1] = col_type(m[1]);
+#		if !GLM_HAS_INITIALIZER_LISTS
+			this->value[0] = col_type(m[0]);
+			this->value[1] = col_type(m[1]);
+#		endif
 	}
 
 	template<typename T, qualifier Q>
 	GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 2, T, Q>::mat(mat<2, 3, T, Q> const& m)
+#		if GLM_HAS_INITIALIZER_LISTS
+			: value{col_type(m[0]), col_type(m[1])}
+#		endif
 	{
-		this->value[0] = col_type(m[0]);
-		this->value[1] = col_type(m[1]);
+#		if !GLM_HAS_INITIALIZER_LISTS
+			this->value[0] = col_type(m[0]);
+			this->value[1] = col_type(m[1]);
+#		endif
 	}
 
 	template<typename T, qualifier Q>
 	GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 2, T, Q>::mat(mat<3, 2, T, Q> const& m)
+#		if GLM_HAS_INITIALIZER_LISTS
+			: value{col_type(m[0]), col_type(m[1])}
+#		endif
 	{
-		this->value[0] = m[0];
-		this->value[1] = m[1];
+#		if !GLM_HAS_INITIALIZER_LISTS
+			this->value[0] = col_type(m[0]);
+			this->value[1] = col_type(m[1]);
+#		endif
 	}
 
 	template<typename T, qualifier Q>
 	GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 2, T, Q>::mat(mat<2, 4, T, Q> const& m)
+#		if GLM_HAS_INITIALIZER_LISTS
+			: value{col_type(m[0]), col_type(m[1])}
+#		endif
 	{
-		this->value[0] = col_type(m[0]);
-		this->value[1] = col_type(m[1]);
+#		if !GLM_HAS_INITIALIZER_LISTS
+			this->value[0] = col_type(m[0]);
+			this->value[1] = col_type(m[1]);
+#		endif
 	}
 
 	template<typename T, qualifier Q>
 	GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 2, T, Q>::mat(mat<4, 2, T, Q> const& m)
+#		if GLM_HAS_INITIALIZER_LISTS
+			: value{col_type(m[0]), col_type(m[1])}
+#		endif
 	{
-		this->value[0] = m[0];
-		this->value[1] = m[1];
+#		if !GLM_HAS_INITIALIZER_LISTS
+			this->value[0] = col_type(m[0]);
+			this->value[1] = col_type(m[1]);
+#		endif
 	}
 
 	template<typename T, qualifier Q>
 	GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 2, T, Q>::mat(mat<3, 4, T, Q> const& m)
+#		if GLM_HAS_INITIALIZER_LISTS
+			: value{col_type(m[0]), col_type(m[1])}
+#		endif
 	{
-		this->value[0] = col_type(m[0]);
-		this->value[1] = col_type(m[1]);
+#		if !GLM_HAS_INITIALIZER_LISTS
+			this->value[0] = col_type(m[0]);
+			this->value[1] = col_type(m[1]);
+#		endif
 	}
 
 	template<typename T, qualifier Q>
 	GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 2, T, Q>::mat(mat<4, 3, T, Q> const& m)
-	{
-		this->value[0] = col_type(m[0]);
-		this->value[1] = col_type(m[1]);
+#		if GLM_HAS_INITIALIZER_LISTS
+			: value{col_type(m[0]), col_type(m[1])}
+#		endif
+	{
+#		if !GLM_HAS_INITIALIZER_LISTS
+			this->value[0] = col_type(m[0]);
+			this->value[1] = col_type(m[1]);
+#		endif
 	}
 
 	// -- Accesses --