diff options
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. */ |