From db3f072dd61cd06ac67f52324f9ca0d21609f508 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Sun, 29 May 2022 17:01:28 +0200 Subject: New o3tl::intcmp.hxx ...introducing o3tl::cmp_equal etc. implementing C++23 std::cmp_equal etc., plus an o3tl::IntCmp wrapper around it for convenient operator syntax Change-Id: I1d2e0d1aef99c531039fb83de31ed8e6036fde03 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135095 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- cppu/source/uno/eq.hxx | 170 ++++++++++++++++++++++++++++--------------------- 1 file changed, 99 insertions(+), 71 deletions(-) (limited to 'cppu/source') diff --git a/cppu/source/uno/eq.hxx b/cppu/source/uno/eq.hxx index e81f0972e801..60a372886776 100644 --- a/cppu/source/uno/eq.hxx +++ b/cppu/source/uno/eq.hxx @@ -20,8 +20,8 @@ #include #include -#include +#include #include #include @@ -260,27 +260,6 @@ inline bool _equalSequence( } } -template -std::enable_if_t && std::is_signed_v, bool> equal(T1 value1, T2 value2) { - return value1 == value2; -} - -template -std::enable_if_t && std::is_unsigned_v, bool> equal(T1 value1, T2 value2) { - return value1 >= 0 && static_cast>(value1) == value2; -} - -template -std::enable_if_t && std::is_signed_v, bool> equal(T1 value1, T2 value2) { - return value2 >= 0 && value1 == static_cast>(value2); -} - -template -std::enable_if_t && std::is_unsigned_v, bool> equal(T1 value1, T2 value2) -{ - return value1 == value2; -} - inline bool _equalData( void * pDest, typelib_TypeDescriptionReference * pDestType, typelib_TypeDescription * pDestTypeDescr, @@ -316,19 +295,26 @@ inline bool _equalData( switch (eSourceTypeClass) { case typelib_TypeClass_BYTE: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_SHORT: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_UNSIGNED_SHORT: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_LONG: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_UNSIGNED_LONG: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_HYPER: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_UNSIGNED_HYPER: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_FLOAT: return (static_cast(*static_cast(pDest)) == *static_cast(pSource)); case typelib_TypeClass_DOUBLE: @@ -340,19 +326,26 @@ inline bool _equalData( switch (eSourceTypeClass) { case typelib_TypeClass_BYTE: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_SHORT: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_UNSIGNED_SHORT: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_LONG: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_UNSIGNED_LONG: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_HYPER: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_UNSIGNED_HYPER: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_FLOAT: return (static_cast(*static_cast(pDest)) == *static_cast(pSource)); case typelib_TypeClass_DOUBLE: @@ -364,19 +357,26 @@ inline bool _equalData( switch (eSourceTypeClass) { case typelib_TypeClass_BYTE: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_SHORT: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_UNSIGNED_SHORT: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_LONG: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_UNSIGNED_LONG: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_HYPER: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_UNSIGNED_HYPER: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_FLOAT: return (static_cast(*static_cast(pDest)) == *static_cast(pSource)); case typelib_TypeClass_DOUBLE: @@ -388,19 +388,26 @@ inline bool _equalData( switch (eSourceTypeClass) { case typelib_TypeClass_BYTE: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_SHORT: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_UNSIGNED_SHORT: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_LONG: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_UNSIGNED_LONG: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_HYPER: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_UNSIGNED_HYPER: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_FLOAT: return (static_cast(*static_cast(pDest)) == *static_cast(pSource)); case typelib_TypeClass_DOUBLE: @@ -412,19 +419,26 @@ inline bool _equalData( switch (eSourceTypeClass) { case typelib_TypeClass_BYTE: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_SHORT: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_UNSIGNED_SHORT: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_LONG: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_UNSIGNED_LONG: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_HYPER: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_UNSIGNED_HYPER: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_FLOAT: return (static_cast(*static_cast(pDest)) == *static_cast(pSource)); case typelib_TypeClass_DOUBLE: @@ -436,19 +450,26 @@ inline bool _equalData( switch (eSourceTypeClass) { case typelib_TypeClass_BYTE: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_SHORT: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_UNSIGNED_SHORT: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_LONG: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_UNSIGNED_LONG: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_HYPER: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_UNSIGNED_HYPER: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_FLOAT: return (static_cast(*static_cast(pDest)) == *static_cast(pSource)); case typelib_TypeClass_DOUBLE: @@ -460,19 +481,26 @@ inline bool _equalData( switch (eSourceTypeClass) { case typelib_TypeClass_BYTE: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_SHORT: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_UNSIGNED_SHORT: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_LONG: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_UNSIGNED_LONG: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_HYPER: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_UNSIGNED_HYPER: - return equal(*static_cast(pDest), *static_cast(pSource)); + return o3tl::cmp_equal( + *static_cast(pDest), *static_cast(pSource)); case typelib_TypeClass_FLOAT: if (::floor( *static_cast(pSource) ) != *static_cast(pSource) || *static_cast(pSource) < 0) return false; -- cgit