Бранимир Караџић 1 year ago
parent
commit
daecc9d9c5
3 changed files with 38 additions and 27 deletions
  1. 10 10
      include/bx/inline/typetraits.inl
  2. 2 2
      include/bx/typetraits.h
  3. 26 15
      tests/typetraits_test.cpp

+ 10 - 10
include/bx/inline/typetraits.inl

@@ -468,9 +468,9 @@ namespace bx
 	template<typename Ty> struct MakeSignedT { using Type = Ty; };
 	template<typename Ty>  using MakeSignedType = typename MakeSignedT<Ty>::Type;
 
-	template<typename Ty> struct MakeSignedT<const          Ty> : AddConstType   <MakeSignedType<Ty>> {};
-	template<typename Ty> struct MakeSignedT<volatile       Ty> : AddVolatileType<MakeSignedType<Ty>> {};
-	template<typename Ty> struct MakeSignedT<const volatile Ty> : AddCvType      <MakeSignedType<Ty>> {};
+	template<typename Ty> struct MakeSignedT<const          Ty> : AddConstT   <MakeSignedType<Ty>> {};
+	template<typename Ty> struct MakeSignedT<volatile       Ty> : AddVolatileT<MakeSignedType<Ty>> {};
+	template<typename Ty> struct MakeSignedT<const volatile Ty> : AddCvT      <MakeSignedType<Ty>> {};
 
 	template<>            struct MakeSignedT<         char     > { using Type = signed char;      };
 	template<>            struct MakeSignedT<  signed char     > { using Type = signed char;      };
@@ -485,18 +485,18 @@ namespace bx
 	template<>            struct MakeSignedT<unsigned long long> { using Type = signed long long; };
 
 	template<typename Ty>
-	inline constexpr auto asSigned(Ty _t)
+	inline constexpr auto asSigned(Ty _value)
 	{
-		return MakeSignedType<Ty>(_t);
+		return MakeSignedType<Ty>(_value);
 	}
 
 	//---
 	template<typename Ty> struct MakeUnsignedT { using Type = Ty; };
 	template<typename Ty>  using MakeUnsignedType = typename MakeUnsignedT<Ty>::Type;
 
-	template<typename Ty> struct MakeUnsignedT<const          Ty> : AddConstType   <MakeUnsignedType<Ty>> {};
-	template<typename Ty> struct MakeUnsignedT<volatile       Ty> : AddVolatileType<MakeUnsignedType<Ty>> {};
-	template<typename Ty> struct MakeUnsignedT<const volatile Ty> : AddCvType      <MakeUnsignedType<Ty>> {};
+	template<typename Ty> struct MakeUnsignedT<const          Ty> : AddConstT   <MakeUnsignedType<Ty>> {};
+	template<typename Ty> struct MakeUnsignedT<volatile       Ty> : AddVolatileT<MakeUnsignedType<Ty>> {};
+	template<typename Ty> struct MakeUnsignedT<const volatile Ty> : AddCvT      <MakeUnsignedType<Ty>> {};
 
 	template<>            struct MakeUnsignedT<         char     > { using Type = unsigned char;      };
 	template<>            struct MakeUnsignedT<  signed char     > { using Type = unsigned char;      };
@@ -511,9 +511,9 @@ namespace bx
 	template<>            struct MakeUnsignedT<unsigned long long> { using Type = unsigned long long; };
 
 	template<typename Ty>
-	inline constexpr auto asUnsigned(Ty _t)
+	inline constexpr auto asUnsigned(Ty _value)
 	{
-		return MakeUnsignedType<Ty>(_t);
+		return MakeUnsignedType<Ty>(_value);
 	}
 
 	//---

+ 2 - 2
include/bx/typetraits.h

@@ -167,11 +167,11 @@ namespace bx
 
 	/// Returns value of `_t` as signed type value.
 	template<typename Ty>
-	constexpr auto asSigned(Ty _t);
+	constexpr auto asSigned(Ty _value);
 
 	/// Returns value of `_t` as unsigned type value.
 	template<typename Ty>
-	constexpr auto asUnsigned(Ty _t);
+	constexpr auto asUnsigned(Ty _value);
 
 	/// Returns true if type `Ty` is integer type, otherwise returns false.
 	template<typename Ty>

+ 26 - 15
tests/typetraits_test.cpp

@@ -227,6 +227,20 @@ TEST_CASE("type-traits isTriviallyDestructible", "")
 	STATIC_REQUIRE(!bx::isTriviallyDestructible<TestClassVirtualDtor >() );
 }
 
+TEST_CASE("type-traits isConst", "")
+{
+	STATIC_REQUIRE(!bx::isConst<char>() );
+	STATIC_REQUIRE( bx::isConst<const char>() );
+	STATIC_REQUIRE( bx::isConst<bx::AddConstType<char>>() );
+}
+
+TEST_CASE("type-traits isVolatile", "")
+{
+	STATIC_REQUIRE(!bx::isVolatile<char>() );
+	STATIC_REQUIRE( bx::isVolatile<volatile char>() );
+	STATIC_REQUIRE( bx::isVolatile<bx::AddVolatileType<char>>() );
+}
+
 TEST_CASE("type-traits isSigned", "")
 {
 	STATIC_REQUIRE(!bx::isSigned<bool                   >() );
@@ -333,17 +347,14 @@ TEST_CASE("type-traits MakeSignedT", "")
 	STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<double                 >::Type >() );
 	STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<long double            >::Type >() );
 
-	enum struct E : unsigned short {};
-	using char_type = std::make_signed_t<unsigned char>;
-	using int_type  = std::make_signed_t<unsigned int>;
-	using long_type = std::make_signed_t<volatile unsigned long>;
-	using enum_type = std::make_signed_t<E>;
+	using charType = bx::MakeSignedType<unsigned char>;
+	using intType  = bx::MakeSignedType<unsigned int>;
+	using longType = bx::MakeSignedType<volatile unsigned long>;
 
 	STATIC_REQUIRE(true
-		&& bx::isSame<char_type, signed char>()
-		&& bx::isSame<int_type, signed int>()
-		&& bx::isSame<long_type, volatile signed long>()
-		&& bx::isSame<enum_type, signed short>()
+		&& bx::isSame<charType, signed char>()
+		&& bx::isSame<intType, signed int>()
+		&& bx::isSame<longType, volatile signed long>()
 		);
 }
 
@@ -377,14 +388,14 @@ TEST_CASE("type-traits MakeUnsignedT", "")
 	STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<ptrdiff_t              >::Type >() );
 	STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<size_t                 >::Type >() );
 
-	using uchar_type = std::make_unsigned_t<char>;
-	using uint_type  = std::make_unsigned_t<int>;
-	using ulong_type = std::make_unsigned_t<volatile long>;
+	using ucharType = bx::MakeUnsignedType<char>;
+	using uintType  = bx::MakeUnsignedType<int>;
+	using ulongType = bx::MakeUnsignedType<volatile long>;
 
 	STATIC_REQUIRE(true
-		&& bx::isSame<uchar_type, unsigned char>()
-		&& bx::isSame<uint_type, unsigned int>()
-		&& bx::isSame<ulong_type, volatile unsigned long>()
+		&& bx::isSame<ucharType, unsigned char>()
+		&& bx::isSame<uintType, unsigned int>()
+		&& bx::isSame<ulongType, volatile unsigned long>()
 		);
 }