From 4c5290e7440b86a89cca62e66e89707dacd887b6 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Sun, 30 Apr 2023 07:02:58 +0200 Subject: [PATCH] Modernize meta programming helpers Use std::declval and remove_reference_t instead of home-baked alternatives. Change-Id: Ia1b3ac6c2d9a6cdba1650c3acb249f2d65bcf94d Reviewed-by: Thiago Macieira --- src/corelib/kernel/qobjectdefs_impl.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/corelib/kernel/qobjectdefs_impl.h b/src/corelib/kernel/qobjectdefs_impl.h index 3951c79fb3..f430749e47 100644 --- a/src/corelib/kernel/qobjectdefs_impl.h +++ b/src/corelib/kernel/qobjectdefs_impl.h @@ -278,10 +278,9 @@ namespace QtPrivate { static_assert(CheckCompatibleArguments::Arguments, FunctionPointer::Arguments>::value) */ template struct AreArgumentsCompatible { - static int test(const typename RemoveRef::Type&); + static int test(const std::remove_reference_t&); static char test(...); - static const typename RemoveRef::Type &dummy(); - enum { value = sizeof(test(dummy())) == sizeof(int) }; + enum { value = sizeof(test(std::declval>())) == sizeof(int) }; #ifdef QT_NO_NARROWING_CONVERSIONS_IN_CONNECT using AreArgumentsConvertibleWithoutNarrowing = AreArgumentsConvertibleWithoutNarrowingBase, std::decay_t>; static_assert(AreArgumentsConvertibleWithoutNarrowing::value, "Signal and slot arguments are not compatible (narrowing)"); @@ -320,11 +319,10 @@ namespace QtPrivate { template struct ComputeFunctorArgumentCount> { - template static D dummy(); - template static auto test(F f) -> decltype(((f.operator()((dummy())...)), int())); + template static auto test(F f) -> decltype(((f.operator()((std::declval())...)), int())); static char test(...); enum { - Ok = sizeof(test(dummy())) == sizeof(int), + Ok = sizeof(test(std::declval())) == sizeof(int), Value = Ok ? int(sizeof...(ArgList)) : int(ComputeFunctorArgumentCountHelper, Ok>::Value) }; }; @@ -332,8 +330,7 @@ namespace QtPrivate { /* get the return type of a functor, given the signal argument list */ template struct FunctorReturnType; template struct FunctorReturnType> { - template static D dummy(); - typedef decltype(dummy().operator()((dummy())...)) Value; + typedef decltype(std::declval().operator()((std::declval())...)) Value; }; /*