Use if constexpr (C++17 feature)

This commit is contained in:
Mat Sutcliffe
2021-04-17 21:57:20 +01:00
parent 5d67cd9f68
commit d7a461ff7a
11 changed files with 103 additions and 189 deletions

View File

@@ -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