mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 00:16:51 +08:00
Use if constexpr (C++17 feature)
This commit is contained in:
@@ -57,10 +57,8 @@ namespace BlackMisc
|
||||
result = true;
|
||||
eventLoop.quit();
|
||||
});
|
||||
if (checkInit(init))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if constexpr (std::is_void_v<decltype(init())>) { init(); }
|
||||
else if (init()) { return true; }
|
||||
if (timeoutMs > 0)
|
||||
{
|
||||
QTimer::singleShot(timeoutMs, &eventLoop, &QEventLoop::quit);
|
||||
@@ -68,20 +66,6 @@ namespace BlackMisc
|
||||
eventLoop.exec();
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename F>
|
||||
static bool checkInit(F init, std::enable_if_t<std::is_void_v<decltype(init())>, int> = 0)
|
||||
{
|
||||
init();
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
static bool checkInit(F init, std::enable_if_t<!std::is_void_v<decltype(init())>, int> = 0)
|
||||
{
|
||||
return init();
|
||||
}
|
||||
};
|
||||
} // ns
|
||||
|
||||
|
||||
Reference in New Issue
Block a user