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
{ {
if constexpr (!IsLayoutPoint<T>::value)
{
return p; return p;
} }
else
//--------------------------------------------------------------------------------------------------------------------- {
template <typename T>
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
{ {
if constexpr (!IsLayoutPoint<T>::value)
{
return matrix.map(obj); return matrix.map(obj);
} }
else
//--------------------------------------------------------------------------------------------------------------------- {
template <typename T>
auto VAbstractPiece::MapPoint(T obj, const QTransform &matrix) ->
typename std::enable_if<IsLayoutPoint<T>::value, T>::type
{
auto p = matrix.map(obj); auto p = matrix.map(obj);
obj.setX(p.x()); obj.setX(p.x());
obj.setY(p.y()); obj.setY(p.y());
return obj; return obj;
}
} }
#endif // VABSTRACTPIECE_H #endif // VABSTRACTPIECE_H