diff options
Diffstat (limited to 'c/common.h')
-rw-r--r-- | c/common.h | 9 |
1 files changed, 4 insertions, 5 deletions
@@ -55,7 +55,7 @@ std::optional<T> maybe_make(U... xs) /* Call Windows API function, throwing error on NULL. */ template <auto F, typename... T> -inline auto throw_nil(T... xs) +inline auto require(T... xs) { auto r = F(xs...); if (!r) throw Win32Error(GetLastError()); @@ -64,15 +64,14 @@ inline auto throw_nil(T... xs) /* Call Windows API function, showing a warning on NULL. */ template <auto F, typename... T> -inline auto warn_nil(T... xs) +inline auto prefer(T... xs) { - decltype(F(std::declval<T>()...)) r; try { - r = throw_nil<F>(xs...); + return require<F>(xs...); } catch (Win32Error& e) { EBMessageBox(e.twhat(), TEXT("System Error"), MB_ICONWARNING); + return (decltype(F(std::declval<T>()...)))NULL; } - return r; } /* Return integer scaled for current DPI. */ |