From 7153a258427d3e401914de800bfdf1c7165cab71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Fri, 15 Jul 2022 03:04:22 +0200 Subject: Replace Library::Load with try_make_unique template. --- c/defs.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'c/defs.h') diff --git a/c/defs.h b/c/defs.h index 766682e..ffebcb0 100644 --- a/c/defs.h +++ b/c/defs.h @@ -13,7 +13,6 @@ struct Library Library(const TCHAR *); ~Library(); FARPROC GetProcAddress(const char *); - static std::unique_ptr Load(const TCHAR *); private: HMODULE m_hModule; }; @@ -144,4 +143,16 @@ inline int Dpi(int i) return MulDiv(i, g_iDPI, 96); } +template +std::unique_ptr try_make_unique(A ...args) +{ + std::unique_ptr up; + try { + up = std::make_unique(args...); + } catch (...) { + up = nullptr; + } + return up; +} + #endif -- cgit v1.2.3