Combine functions with its overloads by using "if constexpr".

This commit is contained in:
Roman Telezhynskyi 2024-02-20 15:59:44 +02:00
parent 5d3ca3c470
commit 634913da34

View File

@ -186,11 +186,7 @@ public:
template <class T> template <class T>
static auto MapVector(QVector<T> points, const QTransform &matrix, bool mirror = false) -> QVector<T>; static auto MapVector(QVector<T> points, const QTransform &matrix, bool mirror = false) -> QVector<T>;
template <class T> template <typename T> static auto MapPoint(T obj, const QTransform &matrix) -> T;
static auto MapPoint(T obj, const QTransform &matrix) -> typename std::enable_if<!IsLayoutPoint<T>::value, T>::type;
template <class T>
static auto MapPoint(T obj, const QTransform &matrix) -> typename std::enable_if<IsLayoutPoint<T>::value, T>::type;
protected: protected:
static auto IsEkvPointOnLine(const QPointF &iPoint, const QPointF &prevPoint, const QPointF &nextPoint) -> bool; static auto IsEkvPointOnLine(const QPointF &iPoint, const QPointF &prevPoint, const QPointF &nextPoint) -> bool;
@ -212,10 +208,7 @@ protected:
private: private:
QSharedDataPointer<VAbstractPieceData> d; QSharedDataPointer<VAbstractPieceData> d;
template <typename T> template <typename T> static auto MakeTurnPoint(const QPointF &p) -> T;
static auto MakeTurnPoint(const QPointF &p) -> typename std::enable_if<!IsLayoutPoint<T>::value, T>::type;
template <typename T>
static auto MakeTurnPoint(const QPointF &p) -> typename std::enable_if<IsLayoutPoint<T>::value, T>::type;
}; };
Q_DECLARE_TYPEINFO(VAbstractPiece, Q_MOVABLE_TYPE); // NOLINT Q_DECLARE_TYPEINFO(VAbstractPiece, Q_MOVABLE_TYPE); // NOLINT
@ -750,20 +743,18 @@ inline auto VAbstractPiece::IntersectionPoint<QPointF>(QPointF crosPoint, const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
template <typename T> template <typename T> inline auto VAbstractPiece::MakeTurnPoint(const QPointF &p) -> T
inline auto VAbstractPiece::MakeTurnPoint(const QPointF &p) ->
typename std::enable_if<!IsLayoutPoint<T>::value, T>::type
{ {
return p; if constexpr (!IsLayoutPoint<T>::value)
} {
return p;
//--------------------------------------------------------------------------------------------------------------------- }
template <typename T> else
inline auto VAbstractPiece::MakeTurnPoint(const QPointF &p) -> typename std::enable_if<IsLayoutPoint<T>::value, T>::type {
{ T breakPoint(p);
T breakPoint(p); breakPoint.SetTurnPoint(true);
breakPoint.SetTurnPoint(true); return breakPoint;
return breakPoint; }
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -958,22 +949,19 @@ inline auto VAbstractPiece::MapVector(QVector<T> points, const QTransform &matri
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
template <typename T> template <typename T> auto VAbstractPiece::MapPoint(T obj, const QTransform &matrix) -> T
auto VAbstractPiece::MapPoint(T obj, const QTransform &matrix) ->
typename std::enable_if<!IsLayoutPoint<T>::value, T>::type
{ {
return matrix.map(obj); if constexpr (!IsLayoutPoint<T>::value)
} {
return matrix.map(obj);
//--------------------------------------------------------------------------------------------------------------------- }
template <typename T> else
auto VAbstractPiece::MapPoint(T obj, const QTransform &matrix) -> {
typename std::enable_if<IsLayoutPoint<T>::value, T>::type auto p = matrix.map(obj);
{ obj.setX(p.x());
auto p = matrix.map(obj); obj.setY(p.y());
obj.setX(p.x()); return obj;
obj.setY(p.y()); }
return obj;
} }
#endif // VABSTRACTPIECE_H #endif // VABSTRACTPIECE_H