aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/qt_connection_util.h6
-rw-r--r--lib/util.h18
2 files changed, 17 insertions, 7 deletions
diff --git a/lib/qt_connection_util.h b/lib/qt_connection_util.h
index 9baf8c69..3c81e3ac 100644
--- a/lib/qt_connection_util.h
+++ b/lib/qt_connection_util.h
@@ -104,7 +104,7 @@ inline auto connectUntil(SenderT* sender, SignalT signal, ContextT* context,
const FunctorT& slot,
Qt::ConnectionType connType = Qt::AutoConnection)
{
- return _impl::connectUntil(sender, signal, context, std::function(slot),
+ return _impl::connectUntil(sender, signal, context, wrap_in_function(slot),
connType);
}
@@ -115,7 +115,7 @@ inline auto connectSingleShot(SenderT* sender, SignalT signal,
Qt::ConnectionType connType = Qt::AutoConnection)
{
return _impl::connectSingleShot(
- sender, signal, context, std::function(slot), connType);
+ sender, signal, context, wrap_in_function(slot), connType);
}
// Specialisation for usual Qt slots passed as pointers-to-members.
@@ -128,7 +128,7 @@ inline auto connectSingleShot(SenderT* sender, SignalT signal,
{
// TODO: when switching to C++20, use std::bind_front() instead
return _impl::connectSingleShot(sender, signal, receiver,
- std::function(
+ wrap_in_function(
[receiver, slot](const ArgTs&... args) {
(receiver->*slot)(args...);
}),
diff --git a/lib/util.h b/lib/util.h
index 4631570f..f7a81b2a 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -149,19 +149,21 @@ namespace _impl {
* https://stackoverflow.com/questions/7943525/is-it-possible-to-figure-out-the-parameter-type-and-return-type-of-a-lambda#7943765
*/
template <typename T>
-struct function_traits : public _impl::fn_traits<void, T> {};
+struct function_traits
+ : public _impl::fn_traits<void, std::remove_reference_t<T>> {};
// Specialisation for a function
template <typename ReturnT, typename... ArgTs>
struct function_traits<ReturnT(ArgTs...)> {
using return_type = ReturnT;
using arg_types = std::tuple<ArgTs...>;
+ // Doesn't (and there's no plan to make it) work for "classic"
+ // member functions (i.e. outside of functors).
+ // See also the comment for wrap_in_function() below
+ using function_type = std::function<ReturnT(ArgTs...)>;
};
namespace _impl {
- template <typename AlwaysVoid, typename T>
- struct fn_traits;
-
// Specialisation for function objects with (non-overloaded) operator()
// (this includes non-generic lambdas)
template <typename T>
@@ -186,6 +188,14 @@ template <typename FnT, int ArgN = 0>
using fn_arg_t =
std::tuple_element_t<ArgN, typename function_traits<FnT>::arg_types>;
+// TODO: get rid of it as soon as Apple Clang gets proper deduction guides
+// for std::function<>
+template <typename FnT>
+inline auto wrap_in_function(FnT&& f)
+{
+ return typename function_traits<FnT>::function_type(std::forward<FnT>(f));
+}
+
inline auto operator"" _ls(const char* s, std::size_t size)
{
return QLatin1String(s, int(size));