diff --git a/doc/changelog.dox b/doc/changelog.dox index 4c6e7b1ca..38c4ef30f 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -123,9 +123,9 @@ See also: @ref Corrade::Utility::Debug::color modifier - Added convenience @ref BoolVector2, @ref BoolVector3 and @ref BoolVector4 typedefs to the root namespace -- New @ref Math::IsScalar, @ref Math::IsVector, @ref Math::IsIntegral and - @ref Math::IsFloatingPoint type traits and a @ref Math::UnderlyingTypeOf - utility +- New @ref Math::IsScalar, @ref Math::IsVector, @ref Math::IsIntegral, + @ref Math::IsFloatingPoint and @ref Math::IsUnitless type traits and a + @ref Math::UnderlyingTypeOf utility @subsubsection changelog-latest-new-platform Platform libraries diff --git a/src/Magnum/Math/Test/TypeTraitsTest.cpp b/src/Magnum/Math/Test/TypeTraitsTest.cpp index 26f7518eb..2f11234e1 100644 --- a/src/Magnum/Math/Test/TypeTraitsTest.cpp +++ b/src/Magnum/Math/Test/TypeTraitsTest.cpp @@ -43,6 +43,7 @@ struct TypeTraitsTest: Corrade::TestSuite::Tester { void isVector(); void isIntegral(); void isFloatingPoint(); + void isUnitless(); void underlyingTypeOf(); @@ -107,6 +108,7 @@ TypeTraitsTest::TypeTraitsTest() { &TypeTraitsTest::isVector, &TypeTraitsTest::isIntegral, &TypeTraitsTest::isFloatingPoint, + &TypeTraitsTest::isUnitless, &TypeTraitsTest::underlyingTypeOf, @@ -231,6 +233,14 @@ void TypeTraitsTest::isFloatingPoint() { CORRADE_VERIFY(!IsFloatingPoint::value); } +void TypeTraitsTest::isUnitless() { + CORRADE_VERIFY(IsUnitless::value); + CORRADE_VERIFY(IsUnitless>::value); + CORRADE_VERIFY(!IsUnitless>::value); + CORRADE_VERIFY(!(IsUnitless>::value)); + CORRADE_VERIFY(!IsUnitless::value); +} + void TypeTraitsTest::underlyingTypeOf() { CORRADE_VERIFY((std::is_same, Int>::value)); CORRADE_VERIFY((std::is_same>, Float>::value)); diff --git a/src/Magnum/Math/TypeTraits.h b/src/Magnum/Math/TypeTraits.h index b7af62bd1..6401feea7 100644 --- a/src/Magnum/Math/TypeTraits.h +++ b/src/Magnum/Math/TypeTraits.h @@ -222,6 +222,24 @@ template struct IsFloatingPoint>: IsFloatingPoint {}; template struct IsFloatingPoint>: IsFloatingPoint {}; #endif +/** +@brief Whether @p T is a unitless tpye + +Equivalent to @ref std::true_type for scalar or vector types that have an +unitless underlying type (i.e., not @ref Deg or @ref Rad); @ref std::false_type +otherwise. Some math functions such as @ref sqrt() or @ref log() work only with +unitless types because the resulting unit couldn't be expressed otherwise. +@see @ref IsScalar, @ref IsVector +*/ +template struct IsUnitless + #ifndef DOXYGEN_GENERATING_OUTPUT + : std::integral_constant::value || IsVector::value> + #endif + {}; +template class Derived, class T> struct IsUnitless>: std::false_type {}; +template struct IsUnitless>: std::false_type {}; +template struct IsUnitless>: std::false_type {}; + namespace Implementation { template struct UnderlyingType { static_assert(IsScalar::value, "type is not scalar");