diff options
author | John Ankarström <john@ankarstrom.se> | 2022-07-20 20:25:59 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-07-20 20:25:59 +0200 |
commit | 3f842c733568aa9068aa83fad52540eb98f334b1 (patch) | |
tree | 398f9f4ac407c96c3cf00755b564fef6b84ea92b /c/common.h | |
parent | 0d5736538a98b2c4001c45d073affc6bc0d772e5 (diff) | |
download | EpisodeBrowser-3f842c733568aa9068aa83fad52540eb98f334b1.tar.gz |
Simplify require, prefer.
Diffstat (limited to 'c/common.h')
-rw-r--r-- | c/common.h | 21 |
1 files changed, 10 insertions, 11 deletions
@@ -55,24 +55,23 @@ std::optional<T> maybe_make(U... xs) } /* Call Windows API function, throwing error on NULL. */ -template <auto F, typename... T> -inline auto require(T... xs) +template <typename T> +inline T require(T x) { - if (auto r = F(xs...)) return r; - else throw Win32Error(); + if (!x) throw Win32Error(); + return x; } /* Call Windows API function, showing a warning on NULL. */ -template <auto F, typename... T> -inline auto prefer(T... xs) +template <typename T> +inline T prefer(T x) { - if (auto r = F(xs...)) - return r; - else { + if (!x) { EBMessageBox(Win32Error().what<TCHAR>(), - TEXT("System Error"), MB_ICONWARNING); - return (decltype(F(std::declval<T>()...)))NULL; + TEXT("System Error"), MB_ICONWARNING); + return (T)NULL; } + return x; } /* Return integer scaled for current DPI. */ |