Tighten template on new QRunnable create method
Only instantiate with object/methods that are invokable with void and returns void. Change-Id: Iab2e43bb8e061e3875a6cca8e06ebbfbfa9e6fe8 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
parent
ebd2fe108a
commit
357ca7d90a
@ -78,13 +78,16 @@ QRunnable::~QRunnable()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template<typename Callable> QRunnable *QRunnable::create(Callable &&callableToRun);
|
||||
\fn template<typename Callable, if_callable<Callable>> QRunnable *QRunnable::create(Callable &&callableToRun);
|
||||
\since 5.15
|
||||
|
||||
Creates a QRunnable that calls \a callableToRun in run().
|
||||
|
||||
Auto-deletion is enabled by default.
|
||||
|
||||
\note This function participates in overload resolution only if \c Callable
|
||||
is a function or function object which can be called with zero arguments.
|
||||
|
||||
\note In Qt versions prior to 6.6, this method took copyable functions only.
|
||||
|
||||
\sa run(), autoDelete()
|
||||
|
@ -24,6 +24,9 @@ public:
|
||||
static QRunnable *create(std::function<void()> functionToRun);
|
||||
#endif
|
||||
template <typename Callable>
|
||||
using if_callable = std::enable_if_t<std::is_invocable_r_v<void, Callable>, bool>;
|
||||
|
||||
template <typename Callable, if_callable<Callable> = true>
|
||||
static QRunnable *create(Callable &&functionToRun);
|
||||
bool autoDelete() const { return m_autoDelete; }
|
||||
void setAutoDelete(bool autoDelete) { m_autoDelete = autoDelete; }
|
||||
@ -76,7 +79,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Callable>
|
||||
template <typename Callable, QRunnable::if_callable<Callable>>
|
||||
QRunnable *QRunnable::create(Callable &&functionToRun)
|
||||
{
|
||||
return new QGenericRunnable(
|
||||
|
Loading…
Reference in New Issue
Block a user