diff --git a/src/blackmisc/invoke.h b/src/blackmisc/invoke.h index ed6137c4c..f19759f70 100644 --- a/src/blackmisc/invoke.h +++ b/src/blackmisc/invoke.h @@ -12,7 +12,9 @@ #ifndef BLACKMISC_INVOKE_H #define BLACKMISC_INVOKE_H -#include +#include +#include "blackmisc/typetraits.h" +#include "blackmisc/integersequence.h" namespace BlackMisc { @@ -38,15 +40,23 @@ namespace BlackMisc } // Like invoke() but ignores the first argument if callable is not a member function. For uniform calling of callables with slot semantics. - template ::value>> - decltype(auto) invokeSlot(F ptr, T *object, Ts &&... args) + template + decltype(auto) invokeSlotImpl(F ptr, T *object, U tuple, index_sequence, std::true_type) { - return (object->*ptr)(std::forward(args)...); + Q_UNUSED(tuple); // in case the pack expansion is empty + return (object->*ptr)(std::forward>(std::get(tuple))...); } - template >::value>> - decltype(auto) invokeSlot(F &&func, T *, Ts &&... args) + template + decltype(auto) invokeSlotImpl(F &&func, T *, U tuple, index_sequence, std::false_type) { - return std::forward(func)(std::forward(args)...); + Q_UNUSED(tuple); // in case the pack expansion is empty + return std::forward(func)(std::forward>(std::get(tuple))...); + } + template + decltype(auto) invokeSlot(F &&func, T *object, Ts &&... args) + { + using seq = MaskSequence, ! TIsQPrivateSignal>::value...>; + return invokeSlotImpl(std::forward(func), object, std::forward_as_tuple(std::forward(args)...), seq(), std::is_member_pointer>()); } } diff --git a/src/blackmisc/typetraits.h b/src/blackmisc/typetraits.h index e92e78982..268f2f57a 100644 --- a/src/blackmisc/typetraits.h +++ b/src/blackmisc/typetraits.h @@ -162,6 +162,16 @@ namespace BlackMisc struct TIsEqualityComparable() == std::declval())>> : public std::true_type {}; //! \endcond + /*! + * Trait that detects if a type is QPrivateSignal. + */ + template > + struct TIsQPrivateSignal : public std::false_type {}; + //! \cond + template + struct TIsQPrivateSignal> : public std::is_same {}; + //! \endcond + } #endif