diff --git a/doc/changelog.dox b/doc/changelog.dox index e5061e1ab..190fad573 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -385,6 +385,8 @@ See also: - @ref Math::sincos() now uses the `__builtin_sincos` intrinsic on GCC, making it potentially faster in case the optimizer doesn't figure out the same +- @ref Math::Vector::operator-() and @ref Math::Vector2::perpendicular() are + now enabled only for signed types to prevent accidents @subsubsection changelog-latest-changes-meshtools MeshTools library diff --git a/src/Magnum/Math/Vector.h b/src/Magnum/Math/Vector.h index 18e4bcdd8..d83712d3a 100644 --- a/src/Magnum/Math/Vector.h +++ b/src/Magnum/Math/Vector.h @@ -313,12 +313,17 @@ template class Vector { /** * @brief Negated vector * - * @f[ + * Enabled only for signed types. @f[ * \boldsymbol b_i = -\boldsymbol a_i * @f] * @see @ref Vector2::perpendicular() */ - Vector operator-() const; + #ifdef DOXYGEN_GENERATING_OUTPUT + Vector + #else + template typename std::enable_if::value, Vector>::type + #endif + operator-() const; /** * @brief Add and assign a vector @@ -1224,7 +1229,8 @@ extern template MAGNUM_EXPORT Corrade::Utility::Debug& operator<<(Corrade::Utili return Math::Vector::pad(a, value); \ } \ \ - Type operator-() const { \ + template typename std::enable_if::value, Type>::type \ + operator-() const { \ return Math::Vector::operator-(); \ } \ Type& operator+=(const Math::Vector& other) { \ @@ -1420,7 +1426,13 @@ template inline BoolVector Vector::ope return out; } -template inline Vector Vector::operator-() const { +template +#ifdef DOXYGEN_GENERATING_OUTPUT +inline Vector +#else +template inline typename std::enable_if::value, Vector>::type +#endif +Vector::operator-() const { Vector out; for(std::size_t i = 0; i != size; ++i) diff --git a/src/Magnum/Math/Vector2.h b/src/Magnum/Math/Vector2.h index 22dddcaa5..f4474db29 100644 --- a/src/Magnum/Math/Vector2.h +++ b/src/Magnum/Math/Vector2.h @@ -149,14 +149,20 @@ template class Vector2: public Vector<2, T> { /** * @brief Perpendicular vector * - * Returns vector rotated 90° counterclockwise. @f[ + * Returns vector rotated 90° counterclockwise. Enabled only for signed + * types. @f[ * \boldsymbol v_\bot = \begin{pmatrix} -v_y \\ v_x \end{pmatrix} * @f] * @see @ref cross(), * @ref dot(const Vector&, const Vector&), * @ref operator-() const */ - Vector2 perpendicular() const { return {-y(), x()}; } + #ifdef DOXYGEN_GENERATING_OUTPUT + Vector2 + #else + template typename std::enable_if::value, Vector2>::type + #endif + perpendicular() const { return {-y(), x()}; } /** * @brief Aspect ratio