include/basegfx/numeric/ftools.hxx | 19 ++++++++++--------- include/o3tl/concepts.hxx | 1 + include/sax/tools/converter.hxx | 3 ++- include/tools/XmlWriter.hxx | 6 ++++-- include/tools/json_writer.hxx | 4 ++-- 5 files changed, 19 insertions(+), 14 deletions(-)
New commits: commit aae3bbca208def0048ef4a2f94d5f6f8cd24cdca Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Mon Jun 2 09:45:51 2025 +0200 Commit: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> CommitDate: Mon Jun 2 09:45:51 2025 +0200 use concepts Change-Id: I776ad35ad13c6952dbdb4d0336cada80ee3963bb diff --git a/include/basegfx/numeric/ftools.hxx b/include/basegfx/numeric/ftools.hxx index 8404dc2babcd..19f0e98c50e9 100644 --- a/include/basegfx/numeric/ftools.hxx +++ b/include/basegfx/numeric/ftools.hxx @@ -23,6 +23,7 @@ #include <cmath> #include <math.h> #include <basegfx/basegfxdllapi.h> +#include <o3tl/concepts.hxx> #include <limits> #include <algorithm> @@ -150,57 +151,57 @@ namespace basegfx inline double getSmallValue() { return 0.000000001f; } /// Compare against small value - template <typename T, std::enable_if_t<std::is_floating_point_v<T>, int> = 0> + template <o3tl::floating_point T> inline bool equalZero(const T& rfVal) { return (fabs(rfVal) <= getSmallValue()); } /// Compare against given small value - template <typename T, std::enable_if_t<std::is_floating_point_v<T>, int> = 0> + template <o3tl::floating_point T> inline bool equalZero(const T& rfVal, const T& rfSmallValue) { return (fabs(rfVal) <= rfSmallValue); } - template <typename T, std::enable_if_t<std::is_floating_point_v<T>, int> = 0> + template <o3tl::floating_point T> inline bool equal(T const& rfValA, T const& rfValB) { // changed to approxEqual usage for better numerical correctness return rtl_math_approxEqual(rfValA, rfValB); } - template <typename T, std::enable_if_t<std::is_floating_point_v<T>, int> = 0> + template <o3tl::floating_point T> inline bool equal(const T& rfValA, const T& rfValB, const T& rfSmallValue) { return (fabs(rfValA - rfValB) <= rfSmallValue); } - template <typename T, std::enable_if_t<std::is_floating_point_v<T>, int> = 0> + template <o3tl::floating_point T> inline bool less(const T& rfValA, const T& rfValB) { return (rfValA < rfValB && !equal(rfValA, rfValB)); } - template <typename T, std::enable_if_t<std::is_floating_point_v<T>, int> = 0> + template <o3tl::floating_point T> inline bool lessOrEqual(const T& rfValA, const T& rfValB) { return (rfValA < rfValB || equal(rfValA, rfValB)); } - template <typename T, std::enable_if_t<std::is_floating_point_v<T>, int> = 0> + template <o3tl::floating_point T> inline bool more(const T& rfValA, const T& rfValB) { return (rfValA > rfValB && !equal(rfValA, rfValB)); } - template <typename T, std::enable_if_t<std::is_floating_point_v<T>, int> = 0> + template <o3tl::floating_point T> inline bool moreOrEqual(const T& rfValA, const T& rfValB) { return (rfValA > rfValB || equal(rfValA, rfValB)); } - template <typename T, std::enable_if_t<std::is_floating_point_v<T>, int> = 0> + template <o3tl::floating_point T> inline bool betweenOrEqualEither(const T& rfValA, const T& rfValB, const T& rfValC) { return (rfValA > rfValB && rfValA < rfValC) || equal(rfValA, rfValB) || equal(rfValA, rfValC); diff --git a/include/o3tl/concepts.hxx b/include/o3tl/concepts.hxx index 07ddcdc459ea..4510956d203a 100644 --- a/include/o3tl/concepts.hxx +++ b/include/o3tl/concepts.hxx @@ -50,6 +50,7 @@ namespace o3tl { template <typename T> concept type_32_bit = sizeof(T) == 4; template <typename T> concept type_64_bit = sizeof(T) == 8; +template <typename T> concept arithmetic = std::is_arithmetic_v<T>; } /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/include/sax/tools/converter.hxx b/include/sax/tools/converter.hxx index 6b18cac11bf4..9c4411f2a62e 100644 --- a/include/sax/tools/converter.hxx +++ b/include/sax/tools/converter.hxx @@ -29,6 +29,7 @@ #include <rtl/strbuf.hxx> #include <sal/types.h> +#include <o3tl/concepts.hxx> #include <rtl/ustrbuf.hxx> #include <com/sun/star/util/MeasureUnit.hpp> #include <tools/color.hxx> @@ -316,7 +317,7 @@ public: static void convertBytesToHexBinary(OUStringBuffer& rBuffer, const void* pBytes, sal_Int32 nBytes); - template <typename T, std::enable_if_t<std::is_arithmetic_v<T>, int> = 0> + template <o3tl::arithmetic T> static void convertNumberToHexBinary(OUStringBuffer& rBuffer, T n) { convertBytesToHexBinary(rBuffer, &n, sizeof(n)); diff --git a/include/tools/XmlWriter.hxx b/include/tools/XmlWriter.hxx index 9c8f82a86f42..6837483ca9ae 100644 --- a/include/tools/XmlWriter.hxx +++ b/include/tools/XmlWriter.hxx @@ -14,6 +14,7 @@ #include <basegfx/numeric/ftools.hxx> #include <tools/toolsdllapi.h> +#include <o3tl/concepts.hxx> #include <rtl/string.hxx> #include <memory> #include <string_view> @@ -59,14 +60,15 @@ public: } void attribute(const char* sTagName, std::u16string_view aValue); void attribute(const char* sTagName, sal_Int64 aNumber); - template <typename T> - requires std::is_arithmetic_v<T> void attribute(const char* sTagName, T aNumber) + + template <o3tl::arithmetic T> void attribute(const char* sTagName, T aNumber) { if constexpr (std::is_floating_point_v<T>) return attribute(sTagName, basegfx::fround64(aNumber)); else return attribute(sTagName, static_cast<sal_Int64>(aNumber)); } + void attributeDouble(const char* sTagName, double aNumber); void attributeBase64(const char* sTagName, std::vector<sal_uInt8> const& rValueInBytes); void attributeBase64(const char* sTagName, std::vector<char> const& rValueInBytes); diff --git a/include/tools/json_writer.hxx b/include/tools/json_writer.hxx index 2977f7f8c231..6f173fc54f1e 100644 --- a/include/tools/json_writer.hxx +++ b/include/tools/json_writer.hxx @@ -11,6 +11,7 @@ #include <sal/config.h> #include <tools/toolsdllapi.h> +#include <o3tl/concepts.hxx> #include <rtl/string.hxx> #include <rtl/ustring.hxx> @@ -63,8 +64,7 @@ public: put(pPropName, std::string_view(pPropVal, N)); } - template <typename N, std::enable_if_t<std::is_arithmetic_v<N>, int> = 0> - void put(std::string_view pPropName, N n) + template <o3tl::arithmetic N> void put(std::string_view pPropName, N n) { putLiteral(pPropName, OString::number(n)); }