From 3f842c733568aa9068aa83fad52540eb98f334b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Wed, 20 Jul 2022 20:25:59 +0200 Subject: Simplify require, prefer. --- c/common.h | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'c/common.h') diff --git a/c/common.h b/c/common.h index 24c98c8..01083b8 100644 --- a/c/common.h +++ b/c/common.h @@ -55,24 +55,23 @@ std::optional maybe_make(U... xs) } /* Call Windows API function, throwing error on NULL. */ -template -inline auto require(T... xs) +template +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 -inline auto prefer(T... xs) +template +inline T prefer(T x) { - if (auto r = F(xs...)) - return r; - else { + if (!x) { EBMessageBox(Win32Error().what(), - TEXT("System Error"), MB_ICONWARNING); - return (decltype(F(std::declval()...)))NULL; + TEXT("System Error"), MB_ICONWARNING); + return (T)NULL; } + return x; } /* Return integer scaled for current DPI. */ -- cgit v1.2.3