From dec3bdff16f1840d2b41b705b07eec44b131d194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 10 Feb 2024 21:58:39 +0100 Subject: [PATCH] Math: make Unit operator*(T, Unit) an inline friend. That accesses the data member directly, similarly to what was done for Vector in 8b1026d457e32357ec18ee2c03c914292a785f77. --- src/Magnum/Math/Unit.h | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Magnum/Math/Unit.h b/src/Magnum/Math/Unit.h index 3c7d73448..5923d8f08 100644 --- a/src/Magnum/Math/Unit.h +++ b/src/Magnum/Math/Unit.h @@ -144,6 +144,22 @@ template class Derived, class T> class Unit { return Unit(_value*number); } + /** + * @brief Multiply a number with a value + * + * Same as @ref operator*(T) const. + */ + constexpr friend Unit operator*( + #ifdef DOXYGEN_GENERATING_OUTPUT + T + #else + typename std::common_type::type + #endif + number, Unit value) + { + return Unit{value._value*number}; + } + /** @brief Divide with a number and assign */ Unit& operator/=(T number) { _value /= number; @@ -164,13 +180,6 @@ template class Derived, class T> class Unit { T _value; }; -/** @relates Unit -@brief Multiply number with value -*/ -template class Derived, class T> constexpr Unit operator*(typename std::common_type::type number, const Unit& value) { - return value*number; -} - }} #endif