From 4da9280a307ced3fab399d655b9d11330fc33bc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Wed, 20 Jul 2022 01:49:36 +0200 Subject: Simplify templates. --- c/common.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'c/common.h') diff --git a/c/common.h b/c/common.h index 7d3f8bd..a4f73e5 100644 --- a/c/common.h +++ b/c/common.h @@ -34,7 +34,7 @@ private: HMODULE m_hModule; }; -template +template T* Library::GetProcAddress(const char* const szProc) { return (T*)(void*)::GetProcAddress(m_hModule, szProc); @@ -43,32 +43,32 @@ T* Library::GetProcAddress(const char* const szProc) /* Create and return an object of type C. If construction fails, * return nothing. The returned value must be checked before being * used, as dereferencing is undefined if the value is empty. */ -template -std::optional maybe_make(T... args) +template +std::optional maybe_make(U... xs) { try { - return C(args...); + return T(xs...); } catch (...) { return {}; } } /* Call Windows API function, throwing error on NULL. */ -template -inline auto throw_nil(T... args) +template +inline auto throw_nil(T... xs) { - auto r = f(args...); + auto r = F(xs...); if (!r) throw Win32Error(GetLastError()); return r; } /* Call Windows API function, showing a warning on NULL. */ -template -inline auto warn_nil(T... args) +template +inline auto warn_nil(T... xs) { - decltype(f(std::declval()...)) r; + decltype(F(std::declval()...)) r; try { - r = throw_nil(args...); + r = throw_nil(xs...); } catch (Win32Error& e) { EBMessageBox(e.twhat(), TEXT("System Error"), MB_ICONWARNING); } -- cgit v1.2.3