basegfx: simplify template code by using concepts

Change-Id: Ie5bff37dbc20253ec869b2e0e0379eb22e78f6d2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180415
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Tested-by: Jenkins
This commit is contained in:
Tomaž Vajngerl
2025-01-17 23:12:18 +09:00
committed by Tomaž Vajngerl
parent 0b3c285ced
commit 76b55ced15
2 changed files with 8 additions and 11 deletions

View File

@@ -10,6 +10,7 @@
#pragma once
#include <o3tl/concepts.hxx>
#include <basegfx/utils/common.hxx>
#include <basegfx/numeric/ftools.hxx>
@@ -68,26 +69,19 @@ public:
// comparators with tolerance
template <typename T = TYPE, std::enable_if_t<std::is_integral_v<T>, int> = 0>
bool equal(const Tuple2D<TYPE>& rTup) const
template <o3tl::integral T = TYPE> bool equal(const Tuple2D<TYPE>& rTup) const
{
return mnX == rTup.mnX && mnY == rTup.mnY;
}
template <typename T = TYPE, std::enable_if_t<std::is_floating_point_v<T>, int> = 0>
bool equal(const Tuple2D<TYPE>& rTup) const
template <o3tl::floating_point T = TYPE> bool equal(const Tuple2D<TYPE>& rTup) const
{
return this == &rTup || (fTools::equal(mnX, rTup.mnX) && fTools::equal(mnY, rTup.mnY));
}
template <typename T = TYPE, std::enable_if_t<std::is_integral_v<T>, int> = 0>
bool equalZero() const
{
return mnX == 0 && mnY == 0;
}
template <o3tl::integral T = TYPE> bool equalZero() const { return mnX == 0 && mnY == 0; }
template <typename T = TYPE, std::enable_if_t<std::is_floating_point_v<T>, int> = 0>
bool equalZero() const
template <o3tl::floating_point T = TYPE> bool equalZero() const
{
return fTools::equalZero(mnX) && fTools::equalZero(mnY);
}

View File

@@ -23,6 +23,7 @@ namespace o3tl
using std::integral;
using std::signed_integral;
using std::unsigned_integral;
using std::floating_point;
}
#else
@@ -38,6 +39,8 @@ template <typename T> concept integral = std::is_integral_v<T>;
template <typename T> concept signed_integral = integral<T>&& std::is_signed_v<T>;
template <typename T> concept unsigned_integral = integral<T> && !signed_integral<T>;
template <typename T> concept floating_point = std::is_floating_point_v<T>;
}
#endif