Browse Source

Added GLM_HAS_MAKE_SIGNED for C++11 support of make_(un)signed

Christophe Riccio 11 years ago
parent
commit
8d9c4596b3
2 changed files with 138 additions and 151 deletions
  1. 4 0
      glm/detail/setup.hpp
  2. 134 151
      glm/detail/type_int.hpp

+ 4 - 0
glm/detail/setup.hpp

@@ -535,6 +535,10 @@
 	((GLM_LANG & GLM_LANG_CXX11_FLAG) && !(GLM_COMPILER & GLM_COMPILER_GCC)) || \
 	((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC12)))
 
+#define GLM_HAS_MAKE_SIGNED (\
+	(GLM_LANG & GLM_LANG_CXX11_FLAG) || \
+	((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC12)))
+
 // OpenMP
 #ifdef _OPENMP 
 #	if GLM_COMPILER & GLM_COMPILER_GCC

+ 134 - 151
glm/detail/type_int.hpp

@@ -29,6 +29,7 @@
 #pragma once
 
 #include "setup.hpp"
+#include <type_traits>
 
 #if GLM_HAS_EXTENDED_INTEGER_TYPE
 #	include <cstdint>
@@ -84,157 +85,139 @@ namespace detail
 	typedef unsigned int					mediump_uint_t;
 	typedef unsigned int					highp_uint_t;
 
-	template <typename genType>
-	struct make_signed
-	{};
-
-	template <>
-	struct make_signed<int8>
-	{
-		typedef int8 type;
-	};
-
-	template <>
-	struct make_signed<uint8>
-	{
-		typedef int8 type;
-	};
-
-	template <>
-	struct make_signed<int16>
-	{
-		typedef int16 type;
-	};
-
-	template <>
-	struct make_signed<uint16>
-	{
-		typedef int16 type;
-	};
-
-	template <>
-	struct make_signed<int32>
-	{
-		typedef int32 type;
-	};
-
-	template <>
-	struct make_signed<uint32>
-	{
-		typedef int32 type;
-	};
-
-	template <>
-	struct make_signed<int64>
-	{
-		typedef int64 type;
-	};
-
-	template <>
-	struct make_signed<uint64>
-	{
-		typedef int64 type;
-	};
-
-	template <>
-	struct make_signed<long>
-	{
-		typedef long type;
-	};
-
-	template <>
-	struct make_signed<long long>
-	{
-		typedef long long type;
-	};
-
-	template <>
-	struct make_signed<unsigned long>
-	{
-		typedef long type;
-	};
-
-	template <>
-	struct make_signed<unsigned long long>
-	{
-		typedef long long type;
-	};
-
-	template <typename genType>
-	struct make_unsigned
-	{};
-
-	template <>
-	struct make_unsigned<int8>
-	{
-		typedef uint8 type;
-	};
-
-	template <>
-	struct make_unsigned<uint8>
-	{
-		typedef uint8 type;
-	};
-
-	template <>
-	struct make_unsigned<int16>
-	{
-		typedef uint16 type;
-	};
-
-	template <>
-	struct make_unsigned<uint16>
-	{
-		typedef uint16 type;
-	};
-
-	template <>
-	struct make_unsigned<int32>
-	{
-		typedef uint32 type;
-	};
-
-	template <>
-	struct make_unsigned<uint32>
-	{
-		typedef uint32 type;
-	};
-
-	template <>
-	struct make_unsigned<int64>
-	{
-		typedef uint64 type;
-	};
-
-	template <>
-	struct make_unsigned<uint64>
-	{
-		typedef uint64 type;
-	};
-
-	template <>
-	struct make_unsigned<long>
-	{
-		typedef unsigned long type;
-	};
-
-	template <>
-	struct make_unsigned<long long>
-	{
-		typedef unsigned long long type;
-	};
-
-	template <>
-	struct make_unsigned<unsigned long>
-	{
-		typedef unsigned long type;
-	};
-
-	template <>
-	struct make_unsigned<unsigned long long>
-	{
-		typedef unsigned long long type;
-	};
+#	if GLM_HAS_MAKE_SIGNED
+		using std::make_signed;
+		using std::make_unsigned;
+
+#	else//GLM_HAS_MAKE_SIGNED
+		template <typename genType>
+		struct make_signed
+		{};
+
+		template <>
+		struct make_signed<char>
+		{
+			typedef char type;
+		};
+
+		template <>
+		struct make_signed<short>
+		{
+			typedef short type;
+		};
+
+		template <>
+		struct make_signed<int>
+		{
+			typedef int type;
+		};
+
+		template <>
+		struct make_signed<long>
+		{
+			typedef long type;
+		};
+
+		template <>
+		struct make_signed<long long>
+		{
+			typedef long long type;
+		};
+
+		template <>
+		struct make_signed<unsigned char>
+		{
+			typedef char type;
+		};
+
+		template <>
+		struct make_signed<unsigned short>
+		{
+			typedef short type;
+		};
+
+		template <>
+		struct make_signed<unsigned int>
+		{
+			typedef int type;
+		};
+
+		template <>
+		struct make_signed<unsigned long>
+		{
+			typedef long type;
+		};
+
+		template <>
+		struct make_signed<unsigned long long>
+		{
+			typedef long long type;
+		};
+
+		template <typename genType>
+		struct make_unsigned
+		{};
+
+		template <>
+		struct make_unsigned<char>
+		{
+			typedef unsigned char type;
+		};
+
+		template <>
+		struct make_unsigned<short>
+		{
+			typedef unsigned short type;
+		};
+
+		template <>
+		struct make_unsigned<int>
+		{
+			typedef unsigned int type;
+		};
+
+		template <>
+		struct make_unsigned<long>
+		{
+			typedef unsigned long type;
+		};
+
+		template <>
+		struct make_unsigned<long long>
+		{
+			typedef unsigned long long type;
+		};
+
+		template <>
+		struct make_unsigned<unsigned char>
+		{
+			typedef unsigned char type;
+		};
+
+		template <>
+		struct make_unsigned<unsigned short>
+		{
+			typedef unsigned short type;
+		};
+
+		template <>
+		struct make_unsigned<unsigned int>
+		{
+			typedef unsigned int type;
+		};
+
+		template <>
+		struct make_unsigned<unsigned long>
+		{
+			typedef unsigned long type;
+		};
+
+		template <>
+		struct make_unsigned<unsigned long long>
+		{
+			typedef unsigned long long type;
+		};
+#	endif//GLM_HAS_MAKE_SIGNED
 }//namespace detail
 
 	typedef detail::int8					int8;