mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 17:35:34 +08:00
refs #794 Private::invokeSlot needs to ignore arguments of type QPrivateSignal.
This commit is contained in:
committed by
Klaus Basan
parent
f709d959d0
commit
ab8dcbad97
@@ -12,7 +12,9 @@
|
||||
#ifndef BLACKMISC_INVOKE_H
|
||||
#define BLACKMISC_INVOKE_H
|
||||
|
||||
#include <type_traits>
|
||||
#include <tuple>
|
||||
#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 <typename F, typename T, typename... Ts, typename = std::enable_if_t<std::is_member_function_pointer<F>::value>>
|
||||
decltype(auto) invokeSlot(F ptr, T *object, Ts &&... args)
|
||||
template <typename F, typename T, typename U, size_t... Is>
|
||||
decltype(auto) invokeSlotImpl(F ptr, T *object, U tuple, index_sequence<Is...>, std::true_type)
|
||||
{
|
||||
return (object->*ptr)(std::forward<Ts>(args)...);
|
||||
Q_UNUSED(tuple); // in case the pack expansion is empty
|
||||
return (object->*ptr)(std::forward<std::tuple_element_t<Is, U>>(std::get<Is>(tuple))...);
|
||||
}
|
||||
template <typename F, typename T, typename... Ts, typename = std::enable_if_t<! std::is_member_pointer<std::decay_t<F>>::value>>
|
||||
decltype(auto) invokeSlot(F &&func, T *, Ts &&... args)
|
||||
template <typename F, typename T, typename U, size_t... Is>
|
||||
decltype(auto) invokeSlotImpl(F &&func, T *, U tuple, index_sequence<Is...>, std::false_type)
|
||||
{
|
||||
return std::forward<F>(func)(std::forward<Ts>(args)...);
|
||||
Q_UNUSED(tuple); // in case the pack expansion is empty
|
||||
return std::forward<F>(func)(std::forward<std::tuple_element_t<Is, U>>(std::get<Is>(tuple))...);
|
||||
}
|
||||
template <typename F, typename T, typename... Ts>
|
||||
decltype(auto) invokeSlot(F &&func, T *object, Ts &&... args)
|
||||
{
|
||||
using seq = MaskSequence<make_index_sequence<sizeof...(Ts)>, ! TIsQPrivateSignal<std::decay_t<Ts>>::value...>;
|
||||
return invokeSlotImpl(std::forward<F>(func), object, std::forward_as_tuple(std::forward<Ts>(args)...), seq(), std::is_member_pointer<std::decay_t<F>>());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -162,6 +162,16 @@ namespace BlackMisc
|
||||
struct TIsEqualityComparable<T, U, void_t<decltype(std::declval<T>() == std::declval<U>())>> : public std::true_type {};
|
||||
//! \endcond
|
||||
|
||||
/*!
|
||||
* Trait that detects if a type is QPrivateSignal.
|
||||
*/
|
||||
template <typename T, typename = void_t<>>
|
||||
struct TIsQPrivateSignal : public std::false_type {};
|
||||
//! \cond
|
||||
template <typename T>
|
||||
struct TIsQPrivateSignal<T, void_t<typename T::QPrivateSignal>> : public std::is_same<T, typename T::QPrivateSignal> {};
|
||||
//! \endcond
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user