From edce20642b6d177ee9877775cbfa9e05ebb4e404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Tue, 2 Aug 2022 23:31:21 +0200 Subject: Replace maybe_make. It seems unnecessary to throw exceptions when simply checking whether a library exists. --- c/common.h | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) (limited to 'c/common.h') diff --git a/c/common.h b/c/common.h index d908d12..0851bb6 100644 --- a/c/common.h +++ b/c/common.h @@ -5,12 +5,6 @@ #include #include -#ifdef UNICODE -#define WA "W" -#else -#define WA "A" -#endif - int EBMessageBox(const wchar_t* wszText, const wchar_t* wszCaption, unsigned uType); int GetRelativeCursorPos(HWND hWnd, POINT* pt); @@ -46,10 +40,12 @@ private: struct Library { + static std::optional Maybe(const wchar_t* lib); Library(const wchar_t* lib); ~Library(); template T* GetProcAddress(const char* szProc); private: + Library(HMODULE hModule); HMODULE m_hModule; }; @@ -65,19 +61,6 @@ inline int wszf(wchar_t (&buf)[N], const wchar_t* const fmt, T... xs) return _snwprintf_s(buf, N, _TRUNCATE, fmt, xs...); } -/* 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(U... xs) -{ - try { - return T(xs...); - } catch (...) { - return {}; - } -} - /* Variable template for caching values from GetSystemMetrics. */ template auto Metric = GetSystemMetrics(I); -- cgit v1.2.3