aboutsummaryrefslogtreecommitdiff
path: root/c/common.h
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-07-20 02:12:32 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-07-20 02:12:32 +0200
commitdf42108d1f4c1628fe62874e48e87282fab6bc65 (patch)
tree76589bd39abd7ec180a9928d49325dbee5d2562b /c/common.h
parent4da9280a307ced3fab399d655b9d11330fc33bc4 (diff)
downloadEpisodeBrowser-df42108d1f4c1628fe62874e48e87282fab6bc65.tar.gz
Fix bug in and rename throw_nil, warn_nil.
In warn_nil, the return value was undefined on exception -- I think. While informative, the names throw_nil and warn_nil don't work very well in conditionals: if (warn_nil<f>(...)) g(); sounds like g should be called if f returns nil and a warning is issued. But it is actually the other way around; g is called if f is successful. if (prefer<f>(...)) g(); sounds less like that.
Diffstat (limited to 'c/common.h')
-rw-r--r--c/common.h9
1 files changed, 4 insertions, 5 deletions
diff --git a/c/common.h b/c/common.h
index a4f73e5..6b29ed5 100644
--- a/c/common.h
+++ b/c/common.h
@@ -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. */