From 4bc84f68153ecff0307a6a314fa62fd91b14dc6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 20 Aug 2019 10:12:33 +0200 Subject: [PATCH] Math: expand UnderlyingTypeOf to support vectors and matrices. This allows getting underlying type of those without needing to include them. Yay. --- src/Magnum/Math/Test/TypeTraitsTest.cpp | 7 ++++++ src/Magnum/Math/TypeTraits.h | 32 ++++++++++++++++++------- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/Magnum/Math/Test/TypeTraitsTest.cpp b/src/Magnum/Math/Test/TypeTraitsTest.cpp index 5580d1ddc..b9b64ba94 100644 --- a/src/Magnum/Math/Test/TypeTraitsTest.cpp +++ b/src/Magnum/Math/Test/TypeTraitsTest.cpp @@ -247,8 +247,15 @@ void TypeTraitsTest::isUnitless() { void TypeTraitsTest::underlyingTypeOf() { CORRADE_VERIFY((std::is_same, Int>::value)); + CORRADE_VERIFY((std::is_same>, Float>::value)); CORRADE_VERIFY((std::is_same>, Double>::value)); + + CORRADE_VERIFY((std::is_same>, UnsignedByte>::value)); + CORRADE_VERIFY((std::is_same>, Float>::value)); + + CORRADE_VERIFY((std::is_same>, Double>::value)); + CORRADE_VERIFY((std::is_same>, Float>::value)); } template void TypeTraitsTest::equalsIntegral() { diff --git a/src/Magnum/Math/TypeTraits.h b/src/Magnum/Math/TypeTraits.h index 7217559d9..ab5e30c19 100644 --- a/src/Magnum/Math/TypeTraits.h +++ b/src/Magnum/Math/TypeTraits.h @@ -250,20 +250,36 @@ namespace Implementation { }; template struct UnderlyingType> { typedef T Type; }; template struct UnderlyingType> { typedef T Type; }; + template struct UnderlyingType> { + typedef T Type; + }; + template struct UnderlyingType> { typedef T Type; }; + template struct UnderlyingType> { typedef T Type; }; + template struct UnderlyingType> { typedef T Type; }; + template struct UnderlyingType> { typedef T Type; }; + template struct UnderlyingType> { typedef T Type; }; + template struct UnderlyingType> { + typedef T Type; + }; + template struct UnderlyingType> { + typedef T Type; + }; + template struct UnderlyingType> { typedef T Type; }; + template struct UnderlyingType> { typedef T Type; }; } /** -@brief Underlying builtin type for a scalar type +@brief Underlying type of a math type -For builtin types returns the type itself, for wrapped types like @ref Deg or -@ref Rad returns the underlying builtin type. It's guaranteed that the input -type is always explicitly convertible to the output type and the output type -is usable with standard APIs such as @ref std::isinf(). +For builtin scalar types returns the type itself, for wrapped types like +@ref Deg or @ref Rad returns the underlying builtin type, for vector and matrix +types the type of their components. -Passed types are required to satisfy @ref IsScalar. All non-scalar Magnum math -types have a member @cpp typedef @ce ``Type`` containing the underlying type. +For scalar types it's guaranteed that the input type is always explicitly +convertible to the output type and the output type is usable with standard APIs +such as @ref std::isinf(). */ -template using UnderlyingTypeOf = typename Implementation::UnderlyingType::Type; +template using UnderlyingTypeOf = typename Implementation::UnderlyingType::Type; namespace Implementation { template struct TypeTraitsDefault {