mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-18 19:35:33 +08:00
refs #457 CWorker support for non-void tasks and thenWithResult().
This commit is contained in:
@@ -185,6 +185,12 @@ namespace BlackMisc
|
||||
return CVariant(QVariant::fromValue(std::forward<T>(value)));
|
||||
}
|
||||
|
||||
//! Call a function and construct a variant from its return value.
|
||||
template <typename F> static CVariant fromResultOf(F &&func)
|
||||
{
|
||||
return fromResultOfImpl(std::forward<F>(func), typename std::is_void<decltype(func())>::type());
|
||||
}
|
||||
|
||||
//! Change the value.
|
||||
template <typename T> void setValue(T &&value) { m_v.setValue(std::forward<T>(value)); }
|
||||
|
||||
@@ -289,6 +295,9 @@ namespace BlackMisc
|
||||
|
||||
static int compareImpl(const CVariant &, const CVariant &);
|
||||
uint getValueHash() const;
|
||||
|
||||
template <typename F> static CVariant fromResultOfImpl(F &&func, std::true_type) { std::forward<F>(func)(); return {}; }
|
||||
template <typename F> static CVariant fromResultOfImpl(F &&func, std::false_type) { return from(std::forward<F>(func)()); }
|
||||
};
|
||||
|
||||
namespace Private
|
||||
|
||||
Reference in New Issue
Block a user