Browse Source

Math: workaround MSVC2015's inability to pick up the float*Unit operator.

Basically the same workaround as was done for Vector in
9cb623eaf9, except that here it doesn't
need the macros for subclasses.
pull/638/head
Vladimír Vondruš 2 years ago
parent
commit
d8bf8b2cfc
  1. 16
      src/Magnum/Math/Unit.h
  2. 3
      src/Magnum/Math/Vector.h

16
src/Magnum/Math/Unit.h

@ -184,6 +184,10 @@ template<template<class> class Derived, class T> class Unit {
* Similar to @ref operator*(T) const, except that the multiplication
* is done in floating-point.
*/
/* Note that this one isn't correctly picked up on MSVC 2015, there's
an out-of-class overload wrapped in CORRADE_MSVC2015_COMPATIBILITY
which is (and the two don't conflict, apparently, so both are
present) */
#ifdef DOXYGEN_GENERATING_OUTPUT
template<class FloatingPoint> constexpr Unit<Derived, T>
#else
@ -292,6 +296,18 @@ template<template<class> class Derived, class T> class Unit {
T _value;
};
#ifdef CORRADE_MSVC2015_COMPATIBILITY
/* MSVC 2015 doesn't correctly pick up the in-class inline friend that does
this, resulting in float*Unit<int> expressions being wrongly executed as
int*Unit<int> due to an implicit conversion fallback. This overload is
picked up correctly (and doesn't conflict with the in-class one). See
UnitTest::multiplyDivideIntegral() for regression tests, the same issue and
a matching workaround is done in Vector as well. */
template<template<class> class Derived, class FloatingPoint, class Integral> constexpr typename std::enable_if<std::is_integral<Integral>::value && std::is_floating_point<FloatingPoint>::value, Unit<Derived, Integral>>::type operator*(FloatingPoint number, const Unit<Derived, Integral>& value) {
return value*number;
}
#endif
}}
#endif

3
src/Magnum/Math/Vector.h

@ -1509,7 +1509,8 @@ extern template MAGNUM_EXPORT Debug& operator<<(Debug&, const Vector<4, Double>&
need to use the MAGNUM_VECTORn_OPERATOR_IMPLEMENTATION() overloads as well
to return a correct subtype. See VectorTest::multiplyDivideIntegral(),
VectorTest::subclass() and corresponding cases in Vector2Test, Vector3Test,
Vector4Test and ColorTest for regression tests. */
Vector4Test and ColorTest for regression tests. The same issue and a
matching workaround is done in Unit as well. */
template<std::size_t size, class FloatingPoint, class Integral> constexpr typename std::enable_if<std::is_integral<Integral>::value && std::is_floating_point<FloatingPoint>::value, Vector<size, Integral>>::type operator*(FloatingPoint scalar, const Vector<size, Integral>& vector) {
return vector*scalar;
}

Loading…
Cancel
Save