From 634913da34608537ea69a8a3b5de53152e909de7 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 20 Feb 2024 15:59:44 +0200 Subject: [PATCH] Combine functions with its overloads by using "if constexpr". --- src/libs/vlayout/vabstractpiece.h | 62 +++++++++++++------------------ 1 file changed, 25 insertions(+), 37 deletions(-) diff --git a/src/libs/vlayout/vabstractpiece.h b/src/libs/vlayout/vabstractpiece.h index f640a72e7..ee78f2c51 100644 --- a/src/libs/vlayout/vabstractpiece.h +++ b/src/libs/vlayout/vabstractpiece.h @@ -186,11 +186,7 @@ public: template static auto MapVector(QVector points, const QTransform &matrix, bool mirror = false) -> QVector; - template - static auto MapPoint(T obj, const QTransform &matrix) -> typename std::enable_if::value, T>::type; - - template - static auto MapPoint(T obj, const QTransform &matrix) -> typename std::enable_if::value, T>::type; + template static auto MapPoint(T obj, const QTransform &matrix) -> T; protected: static auto IsEkvPointOnLine(const QPointF &iPoint, const QPointF &prevPoint, const QPointF &nextPoint) -> bool; @@ -212,10 +208,7 @@ protected: private: QSharedDataPointer d; - template - static auto MakeTurnPoint(const QPointF &p) -> typename std::enable_if::value, T>::type; - template - static auto MakeTurnPoint(const QPointF &p) -> typename std::enable_if::value, T>::type; + template static auto MakeTurnPoint(const QPointF &p) -> T; }; Q_DECLARE_TYPEINFO(VAbstractPiece, Q_MOVABLE_TYPE); // NOLINT @@ -750,20 +743,18 @@ inline auto VAbstractPiece::IntersectionPoint(QPointF crosPoint, const } //--------------------------------------------------------------------------------------------------------------------- -template -inline auto VAbstractPiece::MakeTurnPoint(const QPointF &p) -> - typename std::enable_if::value, T>::type +template inline auto VAbstractPiece::MakeTurnPoint(const QPointF &p) -> T { - return p; -} - -//--------------------------------------------------------------------------------------------------------------------- -template -inline auto VAbstractPiece::MakeTurnPoint(const QPointF &p) -> typename std::enable_if::value, T>::type -{ - T breakPoint(p); - breakPoint.SetTurnPoint(true); - return breakPoint; + if constexpr (!IsLayoutPoint::value) + { + return p; + } + else + { + T breakPoint(p); + breakPoint.SetTurnPoint(true); + return breakPoint; + } } //--------------------------------------------------------------------------------------------------------------------- @@ -958,22 +949,19 @@ inline auto VAbstractPiece::MapVector(QVector points, const QTransform &matri } //--------------------------------------------------------------------------------------------------------------------- -template -auto VAbstractPiece::MapPoint(T obj, const QTransform &matrix) -> - typename std::enable_if::value, T>::type +template auto VAbstractPiece::MapPoint(T obj, const QTransform &matrix) -> T { - return matrix.map(obj); -} - -//--------------------------------------------------------------------------------------------------------------------- -template -auto VAbstractPiece::MapPoint(T obj, const QTransform &matrix) -> - typename std::enable_if::value, T>::type -{ - auto p = matrix.map(obj); - obj.setX(p.x()); - obj.setY(p.y()); - return obj; + if constexpr (!IsLayoutPoint::value) + { + return matrix.map(obj); + } + else + { + auto p = matrix.map(obj); + obj.setX(p.x()); + obj.setY(p.y()); + return obj; + } } #endif // VABSTRACTPIECE_H