mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Added MakeSignedT and MakeUnsignedT to type traits.
This commit is contained in:
@@ -464,6 +464,58 @@ namespace bx
|
||||
return IsUnsignedT<Ty>::value;
|
||||
}
|
||||
|
||||
//---
|
||||
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<> struct MakeSignedT< char > { using Type = signed char; };
|
||||
template<> struct MakeSignedT< signed char > { using Type = signed char; };
|
||||
template<> struct MakeSignedT<unsigned char > { using Type = signed char; };
|
||||
template<> struct MakeSignedT< short > { using Type = signed short; };
|
||||
template<> struct MakeSignedT<unsigned short > { using Type = signed short; };
|
||||
template<> struct MakeSignedT< int > { using Type = signed int; };
|
||||
template<> struct MakeSignedT<unsigned int > { using Type = signed int; };
|
||||
template<> struct MakeSignedT< long > { using Type = signed long; };
|
||||
template<> struct MakeSignedT<unsigned long > { using Type = signed long; };
|
||||
template<> struct MakeSignedT< long long> { using Type = signed long long; };
|
||||
template<> struct MakeSignedT<unsigned long long> { using Type = signed long long; };
|
||||
|
||||
template<typename Ty>
|
||||
inline constexpr auto asSigned(Ty _t)
|
||||
{
|
||||
return MakeSignedType<Ty>(_t);
|
||||
}
|
||||
|
||||
//---
|
||||
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<> struct MakeUnsignedT< char > { using Type = unsigned char; };
|
||||
template<> struct MakeUnsignedT< signed char > { using Type = unsigned char; };
|
||||
template<> struct MakeUnsignedT<unsigned char > { using Type = unsigned char; };
|
||||
template<> struct MakeUnsignedT< short > { using Type = unsigned short; };
|
||||
template<> struct MakeUnsignedT<unsigned short > { using Type = unsigned short; };
|
||||
template<> struct MakeUnsignedT< int > { using Type = unsigned int; };
|
||||
template<> struct MakeUnsignedT<unsigned int > { using Type = unsigned int; };
|
||||
template<> struct MakeUnsignedT< long > { using Type = unsigned long; };
|
||||
template<> struct MakeUnsignedT<unsigned long > { using Type = unsigned long; };
|
||||
template<> struct MakeUnsignedT< long long> { using Type = unsigned long long; };
|
||||
template<> struct MakeUnsignedT<unsigned long long> { using Type = unsigned long long; };
|
||||
|
||||
template<typename Ty>
|
||||
inline constexpr auto asUnsigned(Ty _t)
|
||||
{
|
||||
return MakeUnsignedType<Ty>(_t);
|
||||
}
|
||||
|
||||
//---
|
||||
template<typename Ty> struct IsIntegerT : FalseConstant {};
|
||||
template<> struct IsIntegerT<bool > : TrueConstant {};
|
||||
|
||||
@@ -165,6 +165,14 @@ namespace bx
|
||||
template<typename Ty>
|
||||
constexpr bool isUnsigned();
|
||||
|
||||
/// Returns value of `_t` as signed type value.
|
||||
template<typename Ty>
|
||||
constexpr auto asSigned(Ty _t);
|
||||
|
||||
/// Returns value of `_t` as unsigned type value.
|
||||
template<typename Ty>
|
||||
constexpr auto asUnsigned(Ty _t);
|
||||
|
||||
/// Returns true if type `Ty` is integer type, otherwise returns false.
|
||||
template<typename Ty>
|
||||
constexpr bool isInteger();
|
||||
|
||||
Reference in New Issue
Block a user