Sfoglia il codice sorgente

Added support of defaulted functions to *vec* types #366

Christophe Riccio 10 anni fa
parent
commit
f7751bfb06

+ 8 - 1
glm/detail/setup.hpp

@@ -619,7 +619,8 @@
 #else
 #	define GLM_HAS_DEFAULTED_FUNCTIONS (GLM_LANG & GLM_LANG_CXX0X_FLAG) && (\
 		((GLM_COMPILER & GLM_COMPILER_GCC) && (GLM_COMPILER >= GLM_COMPILER_GCC44)) || \
-		((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC2013)))
+		((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC2013)) || \
+		((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_COMPILER >= GLM_COMPILER_INTEL12)))
 #endif
 
 // N2118
@@ -923,6 +924,12 @@
 #	define GLM_RESTRICT_VAR
 #endif//GLM_COMPILER
 
+#if GLM_HAS_DEFAULTED_FUNCTIONS
+#	define GLM_DEFAULT = default
+#else
+#	define GLM_DEFAULT
+#endif
+
 #if GLM_HAS_CONSTEXPR
 #	define GLM_CONSTEXPR constexpr
 #	define GLM_RELAXED_CONSTEXPR constexpr

+ 3 - 3
glm/detail/type_vec1.hpp

@@ -112,8 +112,8 @@ namespace glm
 		//////////////////////////////////////
 		// Implicit basic constructors
 
-		GLM_FUNC_DECL tvec1();
-		GLM_FUNC_DECL tvec1(tvec1<T, P> const & v);
+		GLM_FUNC_DECL tvec1() GLM_DEFAULT;
+		GLM_FUNC_DECL tvec1(tvec1<T, P> const & v) GLM_DEFAULT;
 		template <precision Q>
 		GLM_FUNC_DECL tvec1(tvec1<T, Q> const & v);
 
@@ -154,7 +154,7 @@ namespace glm
 		//////////////////////////////////////
 		// Unary arithmetic operators
 
-		GLM_FUNC_DECL tvec1<T, P> & operator=(tvec1<T, P> const & v);
+		GLM_FUNC_DECL tvec1<T, P> & operator=(tvec1<T, P> const & v) GLM_DEFAULT;
 
 		template <typename U>
 		GLM_FUNC_DECL tvec1<T, P> & operator=(tvec1<U, P> const & v);

+ 20 - 16
glm/detail/type_vec1.inl

@@ -35,17 +35,19 @@ namespace glm
 	//////////////////////////////////////
 	// Implicit basic constructors
 
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec1<T, P>::tvec1()
-#		ifndef GLM_FORCE_NO_CTOR_INIT
-			: x(0)
-#		endif
-	{}
+#	if !GLM_HAS_DEFAULTED_FUNCTIONS
+		template <typename T, precision P>
+		GLM_FUNC_QUALIFIER tvec1<T, P>::tvec1()
+#			ifndef GLM_FORCE_NO_CTOR_INIT
+				: x(0)
+#			endif
+		{}
 
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec1<T, P>::tvec1(tvec1<T, P> const & v)
-		: x(v.x)
-	{}
+		template <typename T, precision P>
+		GLM_FUNC_QUALIFIER tvec1<T, P>::tvec1(tvec1<T, P> const & v)
+			: x(v.x)
+		{}
+#	endif//!GLM_HAS_DEFAULTED_FUNCTIONS
 
 	template <typename T, precision P>
 	template <precision Q>
@@ -140,12 +142,14 @@ namespace glm
 	//////////////////////////////////////
 	// Unary arithmetic operators
 
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator=(tvec1<T, P> const & v)
-	{
-		this->x = v.x;
-		return *this;
-	}
+#	if !GLM_HAS_DEFAULTED_FUNCTIONS
+		template <typename T, precision P>
+		GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator=(tvec1<T, P> const & v)
+		{
+			this->x = v.x;
+			return *this;
+		}
+#	endif//!GLM_HAS_DEFAULTED_FUNCTIONS
 
 	template <typename T, precision P>
 	template <typename U> 

+ 3 - 3
glm/detail/type_vec2.hpp

@@ -113,8 +113,8 @@ namespace glm
 		//////////////////////////////////////
 		// Implicit basic constructors
 
-		GLM_FUNC_DECL tvec2();
-		GLM_FUNC_DECL tvec2(tvec2<T, P> const & v);
+		GLM_FUNC_DECL tvec2() GLM_DEFAULT;
+		GLM_FUNC_DECL tvec2(tvec2<T, P> const & v) GLM_DEFAULT;
 		template <precision Q>
 		GLM_FUNC_DECL tvec2(tvec2<T, Q> const & v);
 
@@ -162,7 +162,7 @@ namespace glm
 		//////////////////////////////////////
 		// Unary arithmetic operators
 
-		GLM_FUNC_DECL tvec2<T, P>& operator=(tvec2<T, P> const & v);
+		GLM_FUNC_DECL tvec2<T, P>& operator=(tvec2<T, P> const & v) GLM_DEFAULT;
 
 		template <typename U>
 		GLM_FUNC_DECL tvec2<T, P>& operator=(tvec2<U, P> const & v);

+ 66 - 48
glm/detail/type_vec2.inl

@@ -28,51 +28,22 @@
 
 namespace glm
 {
-#ifdef GLM_FORCE_SIZE_FUNC
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER GLM_CONSTEXPR size_t tvec2<T, P>::size() const
-	{
-		return 2;
-	}
-#else
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER GLM_CONSTEXPR length_t tvec2<T, P>::length() const
-	{
-		return 2;
-	}
-#endif
-
-	//////////////////////////////////////
-	// Accesses
-
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER T & tvec2<T, P>::operator[](length_t i)
-	{
-		assert(i >= 0 && static_cast<detail::component_count_t>(i) < detail::component_count(*this));
-		return (&x)[i];
-	}
-
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER T const & tvec2<T, P>::operator[](length_t i) const
-	{
-		assert(i >= 0 && static_cast<detail::component_count_t>(i) < detail::component_count(*this));
-		return (&x)[i];
-	}
-
 	//////////////////////////////////////
 	// Implicit basic constructors
 
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec2<T, P>::tvec2()
-#		ifndef GLM_FORCE_NO_CTOR_INIT
-			: x(0), y(0)
-#		endif
-	{}
+#	if !GLM_HAS_DEFAULTED_FUNCTIONS
+		template <typename T, precision P>
+		GLM_FUNC_QUALIFIER tvec2<T, P>::tvec2()
+#			ifndef GLM_FORCE_NO_CTOR_INIT
+				: x(0), y(0)
+#			endif
+		{}
 
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec2<T, P>::tvec2(tvec2<T, P> const & v)
-		: x(v.x), y(v.y)
-	{}
+		template <typename T, precision P>
+		GLM_FUNC_QUALIFIER tvec2<T, P>::tvec2(tvec2<T, P> const & v)
+			: x(v.x), y(v.y)
+		{}
+#	endif//!GLM_HAS_DEFAULTED_FUNCTIONS
 
 	template <typename T, precision P>
 	template <precision Q>
@@ -138,16 +109,63 @@ namespace glm
 		, y(static_cast<T>(v.y))
 	{}
 
+	//////////////////////////////////////
+	// Component accesses
+
+#	ifdef GLM_FORCE_SIZE_FUNC
+		template <typename T, precision P>
+		GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename tvec2<T, P>::size_type tvec2<T, P>::size() const
+		{
+			return 2;
+		}
+
+		template <typename T, precision P>
+		GLM_FUNC_QUALIFIER T & tvec2<T, P>::operator[](typename tvec2<T, P>::size_type i)
+		{
+			assert(i >= 0 && static_cast<detail::component_count_t>(i) < detail::component_count(*this));
+			return (&x)[i];
+		}
+
+		template <typename T, precision P>
+		GLM_FUNC_QUALIFIER T const & tvec2<T, P>::operator[](typename tvec2<T, P>::size_type i) const
+		{
+			assert(i >= 0 && static_cast<detail::component_count_t>(i) < detail::component_count(*this));
+			return (&x)[i];
+		}
+#	else
+		template <typename T, precision P>
+		GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename tvec2<T, P>::length_type tvec2<T, P>::length() const
+		{
+			return 2;
+		}
+
+		template <typename T, precision P>
+		GLM_FUNC_QUALIFIER T & tvec2<T, P>::operator[](typename tvec2<T, P>::length_type i)
+		{
+			assert(i >= 0 && static_cast<detail::component_count_t>(i) < detail::component_count(*this));
+			return (&x)[i];
+		}
+
+		template <typename T, precision P>
+		GLM_FUNC_QUALIFIER T const & tvec2<T, P>::operator[](typename tvec2<T, P>::length_type i) const
+		{
+			assert(i >= 0 && static_cast<detail::component_count_t>(i) < detail::component_count(*this));
+			return (&x)[i];
+		}
+#	endif//GLM_FORCE_SIZE_FUNC
+
 	//////////////////////////////////////
 	// Unary arithmetic operators
 
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec2<T, P> & tvec2<T, P>::operator=(tvec2<T, P> const & v)
-	{
-		this->x = v.x;
-		this->y = v.y;
-		return *this;
-	}
+#	if !GLM_HAS_DEFAULTED_FUNCTIONS
+		template <typename T, precision P>
+		GLM_FUNC_QUALIFIER tvec2<T, P> & tvec2<T, P>::operator=(tvec2<T, P> const & v)
+		{
+			this->x = v.x;
+			this->y = v.y;
+			return *this;
+		}
+#	endif//!GLM_HAS_DEFAULTED_FUNCTIONS
 
 	template <typename T, precision P>
 	template <typename U>

+ 3 - 3
glm/detail/type_vec3.hpp

@@ -114,8 +114,8 @@ namespace glm
 		//////////////////////////////////////
 		// Implicit basic constructors
 
-		GLM_FUNC_DECL tvec3();
-		GLM_FUNC_DECL tvec3(tvec3<T, P> const & v);
+		GLM_FUNC_DECL tvec3() GLM_DEFAULT;
+		GLM_FUNC_DECL tvec3(tvec3<T, P> const & v) GLM_DEFAULT;
 		template <precision Q>
 		GLM_FUNC_DECL tvec3(tvec3<T, Q> const & v);
 
@@ -184,7 +184,7 @@ namespace glm
 		//////////////////////////////////////
 		// Unary arithmetic operators
 
-		GLM_FUNC_DECL tvec3<T, P> & operator=(tvec3<T, P> const & v);
+		GLM_FUNC_DECL tvec3<T, P> & operator=(tvec3<T, P> const & v) GLM_DEFAULT;
 
 		template <typename U>
 		GLM_FUNC_DECL tvec3<T, P> & operator=(tvec3<U, P> const & v);

+ 22 - 18
glm/detail/type_vec3.inl

@@ -35,17 +35,19 @@ namespace glm
 	//////////////////////////////////////
 	// Implicit basic constructors
 
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec3<T, P>::tvec3()
-#		ifndef GLM_FORCE_NO_CTOR_INIT 
-			: x(0), y(0), z(0)
-#		endif
-	{}
+#	if !GLM_HAS_DEFAULTED_FUNCTIONS
+		template <typename T, precision P>
+		GLM_FUNC_QUALIFIER tvec3<T, P>::tvec3()
+#			ifndef GLM_FORCE_NO_CTOR_INIT 
+				: x(0), y(0), z(0)
+#			endif
+		{}
 
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec3<T, P>::tvec3(tvec3<T, P> const & v)
-		: x(v.x), y(v.y), z(v.z)
-	{}
+		template <typename T, precision P>
+		GLM_FUNC_QUALIFIER tvec3<T, P>::tvec3(tvec3<T, P> const & v)
+			: x(v.x), y(v.y), z(v.z)
+		{}
+#	endif//!GLM_HAS_DEFAULTED_FUNCTIONS
 
 	template <typename T, precision P>
 	template <precision Q>
@@ -188,14 +190,16 @@ namespace glm
 	//////////////////////////////////////
 	// Unary arithmetic operators
 
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec3<T, P>& tvec3<T, P>::operator=(tvec3<T, P> const & v)
-	{
-		this->x = v.x;
-		this->y = v.y;
-		this->z = v.z;
-		return *this;
-	}
+#	if !GLM_HAS_DEFAULTED_FUNCTIONS
+		template <typename T, precision P>
+		GLM_FUNC_QUALIFIER tvec3<T, P>& tvec3<T, P>::operator=(tvec3<T, P> const & v)
+		{
+			this->x = v.x;
+			this->y = v.y;
+			this->z = v.z;
+			return *this;
+		}
+#	endif//!GLM_HAS_DEFAULTED_FUNCTIONS
 
 	template <typename T, precision P>
 	template <typename U>

+ 3 - 4
glm/detail/type_vec4.hpp

@@ -171,8 +171,8 @@ namespace detail
 		//////////////////////////////////////
 		// Implicit basic constructors
 
-		GLM_FUNC_DECL tvec4();
-		GLM_FUNC_DECL tvec4(tvec4<T, P> const & v);
+		GLM_FUNC_DECL tvec4() GLM_DEFAULT;
+		GLM_FUNC_DECL tvec4(tvec4<T, P> const & v) GLM_DEFAULT;
 		template <precision Q>
 		GLM_FUNC_DECL tvec4(tvec4<T, Q> const & v);
 
@@ -182,7 +182,6 @@ namespace detail
 		GLM_FUNC_DECL explicit tvec4(ctor);
 		GLM_FUNC_DECL explicit tvec4(T s);
 		GLM_FUNC_DECL tvec4(T a, T b, T c, T d);
-		GLM_FUNC_DECL ~tvec4(){}
 
 		//////////////////////////////////////
 		// Conversion scalar constructors
@@ -284,7 +283,7 @@ namespace detail
 		//////////////////////////////////////
 		// Unary arithmetic operators
 
-		GLM_FUNC_DECL tvec4<T, P> & operator=(tvec4<T, P> const & v);
+		GLM_FUNC_DECL tvec4<T, P> & operator=(tvec4<T, P> const & v) GLM_DEFAULT;
 
 		template <typename U>
 		GLM_FUNC_DECL tvec4<T, P> & operator=(tvec4<U, P> const & v);

+ 23 - 19
glm/detail/type_vec4.inl

@@ -35,17 +35,19 @@ namespace glm
 	//////////////////////////////////////
 	// Implicit basic constructors
 
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec4<T, P>::tvec4()
-#		ifndef GLM_FORCE_NO_CTOR_INIT
-			: x(0), y(0), z(0), w(0)
-#		endif
-	{}
+#	if !GLM_HAS_DEFAULTED_FUNCTIONS
+		template <typename T, precision P>
+		GLM_FUNC_QUALIFIER tvec4<T, P>::tvec4()
+#			ifndef GLM_FORCE_NO_CTOR_INIT
+				: x(0), y(0), z(0), w(0)
+#			endif
+		{}
 
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec4<T, P>::tvec4(tvec4<T, P> const & v)
-		: x(v.x), y(v.y), z(v.z), w(v.w)
-	{}
+		template <typename T, precision P>
+		GLM_FUNC_QUALIFIER tvec4<T, P>::tvec4(tvec4<T, P> const & v)
+			: x(v.x), y(v.y), z(v.z), w(v.w)
+		{}
+#	endif//!GLM_HAS_DEFAULTED_FUNCTIONS
 
 	template <typename T, precision P>
 	template <precision Q>
@@ -250,15 +252,17 @@ namespace glm
 	//////////////////////////////////////
 	// Unary arithmetic operators
 
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec4<T, P> & tvec4<T, P>::operator=(tvec4<T, P> const & v)
-	{
-		this->x = v.x;
-		this->y = v.y;
-		this->z = v.z;
-		this->w = v.w;
-		return *this;
-	}
+#	if !GLM_HAS_DEFAULTED_FUNCTIONS
+		template <typename T, precision P>
+		GLM_FUNC_QUALIFIER tvec4<T, P> & tvec4<T, P>::operator=(tvec4<T, P> const & v)
+		{
+			this->x = v.x;
+			this->y = v.y;
+			this->z = v.z;
+			this->w = v.w;
+			return *this;
+		}
+#	endif//!GLM_HAS_DEFAULTED_FUNCTIONS
 
 	template <typename T, precision P>
 	template <typename U>

+ 14 - 16
glm/detail/type_vec4_sse2.inl

@@ -31,24 +31,22 @@
 ///////////////////////////////////////////////////////////////////////////////////
 
 namespace glm{
-namespace detail
-{
 
-}//namespace detail
-
-	template <>
-	GLM_FUNC_QUALIFIER tvec4<float, lowp>::tvec4()
-#		ifndef GLM_FORCE_NO_CTOR_INIT
-			: data(_mm_setzero_ps())
-#		endif
-	{}
+#	if !GLM_HAS_DEFAULTED_FUNCTIONS
+		template <>
+		GLM_FUNC_QUALIFIER tvec4<float, lowp>::tvec4()
+#			ifndef GLM_FORCE_NO_CTOR_INIT
+				: data(_mm_setzero_ps())
+#			endif
+		{}
 	
-	template <>
-	GLM_FUNC_QUALIFIER tvec4<float, mediump>::tvec4()
-#		ifndef GLM_FORCE_NO_CTOR_INIT
-			: data(_mm_setzero_ps())
-#		endif
-	{}
+		template <>
+		GLM_FUNC_QUALIFIER tvec4<float, mediump>::tvec4()
+#			ifndef GLM_FORCE_NO_CTOR_INIT
+				: data(_mm_setzero_ps())
+#			endif
+		{}
+#	endif//!GLM_HAS_DEFAULTED_FUNCTIONS
 
 	template <>
 	GLM_FUNC_QUALIFIER tvec4<float, lowp>::tvec4(float s) :

+ 16 - 0
test/core/core_type_vec1.cpp

@@ -69,6 +69,22 @@ int test_vec1_ctor()
 {
 	int Error = 0;
 
+#	if GLM_HAS_DEFAULTED_FUNCTIONS
+	{
+		union pack
+		{
+			glm::vec1 f;
+			glm::ivec1 i;
+		} A, B;
+
+		A.f = glm::vec1(0);
+		Error += glm::all(glm::equal(A.i, glm::ivec1(0))) ? 0 : 1;
+
+		B.f = glm::vec1(1);
+		Error += glm::all(glm::equal(B.i, glm::ivec1(1065353216))) ? 0 : 1;
+	}
+#	endif//GLM_HAS_DEFAULTED_FUNCTIONS
+
 #	if GLM_HAS_TRIVIAL_QUERIES
 	//	Error += std::is_trivially_default_constructible<glm::vec1>::value ? 0 : 1;
 	//	Error += std::is_trivially_copy_assignable<glm::vec1>::value ? 0 : 1;

+ 16 - 0
test/core/core_type_vec2.cpp

@@ -229,6 +229,22 @@ int test_vec2_ctor()
 {
 	int Error = 0;
 
+#	if GLM_HAS_DEFAULTED_FUNCTIONS
+	{
+		union pack
+		{
+			glm::vec2 f;
+			glm::ivec2 i;
+		} A, B;
+
+		A.f = glm::vec2(0);
+		Error += glm::all(glm::equal(A.i, glm::ivec2(0))) ? 0 : 1;
+
+		B.f = glm::vec2(1);
+		Error += glm::all(glm::equal(B.i, glm::ivec2(1065353216))) ? 0 : 1;
+	}
+#	endif//GLM_HAS_DEFAULTED_FUNCTIONS
+
 #	if GLM_HAS_TRIVIAL_QUERIES
 	//	Error += std::is_trivially_default_constructible<glm::vec2>::value ? 0 : 1;
 	//	Error += std::is_trivially_copy_assignable<glm::vec2>::value ? 0 : 1;

+ 16 - 0
test/core/core_type_vec3.cpp

@@ -45,6 +45,22 @@ int test_vec3_ctor()
 {
 	int Error = 0;
 
+#	if GLM_HAS_DEFAULTED_FUNCTIONS
+	{
+		union pack
+		{
+			glm::vec3 f;
+			glm::ivec3 i;
+		} A, B;
+
+		A.f = glm::vec3(0);
+		Error += glm::all(glm::equal(A.i, glm::ivec3(0))) ? 0 : 1;
+
+		B.f = glm::vec3(1);
+		Error += glm::all(glm::equal(B.i, glm::ivec3(1065353216))) ? 0 : 1;
+	}
+#	endif//GLM_HAS_DEFAULTED_FUNCTIONS
+
 #	if GLM_HAS_TRIVIAL_QUERIES
 	//	Error += std::is_trivially_default_constructible<glm::vec3>::value ? 0 : 1;
 	//	Error += std::is_trivially_copy_assignable<glm::vec3>::value ? 0 : 1;

+ 16 - 0
test/core/core_type_vec4.cpp

@@ -68,6 +68,22 @@ int test_vec4_ctor()
 {
 	int Error = 0;
 
+#	if GLM_HAS_DEFAULTED_FUNCTIONS
+	{
+		union pack
+		{
+			glm::vec4 f;
+			glm::ivec4 i;
+		} A, B;
+
+		A.f = glm::vec4(0);
+		Error += glm::all(glm::equal(A.i, glm::ivec4(0))) ? 0 : 1;
+
+		B.f = glm::vec4(1);
+		Error += glm::all(glm::equal(B.i, glm::ivec4(1065353216))) ? 0 : 1;
+	}
+#	endif//GLM_HAS_DEFAULTED_FUNCTIONS
+
 	{
 		glm::ivec4 A(1, 2, 3, 4);
 		glm::ivec4 B(A);