aboutsummaryrefslogtreecommitdiff
path: root/c
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-07-15 12:03:15 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-07-15 12:03:15 +0200
commit85a6d12a647a63e578260e942dec844d2f5ab66e (patch)
treefef16cfbec2abc8a6b6c837dd9d5cf938bcd749c /c
parent7153a258427d3e401914de800bfdf1c7165cab71 (diff)
downloadEpisodeBrowser-85a6d12a647a63e578260e942dec844d2f5ab66e.tar.gz
Use std::optional instead of std::unique_ptr for try_make.
This requires C++17.
Diffstat (limited to 'c')
-rw-r--r--c/defs.h9
-rw-r--r--c/main.cpp8
2 files changed, 8 insertions, 9 deletions
diff --git a/c/defs.h b/c/defs.h
index ffebcb0..c8d76b3 100644
--- a/c/defs.h
+++ b/c/defs.h
@@ -2,6 +2,7 @@
#define DEFS_H
#include <memory>
+#include <optional>
#include <windows.h>
#include <commctrl.h>
#include <SWI-Prolog.h>
@@ -144,15 +145,13 @@ inline int Dpi(int i)
}
template <class T, typename ...A>
-std::unique_ptr<T> try_make_unique(A ...args)
+std::optional<T> try_make(A ...args)
{
- std::unique_ptr<T> up;
try {
- up = std::make_unique<T>(args...);
+ return T(args...);
} catch (...) {
- up = nullptr;
+ return {};
}
- return up;
}
#endif
diff --git a/c/main.cpp b/c/main.cpp
index 8bf07fb..f0adee9 100644
--- a/c/main.cpp
+++ b/c/main.cpp
@@ -35,14 +35,14 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR tszErr;
/* Set constant values. */
- if (auto upLib = try_make_unique<Library>(TEXT("uxtheme.dll")))
+ if (auto upLib = try_make<Library>(TEXT("uxtheme.dll")))
if (upLib->GetProcAddress("SetWindowTheme")) {
g_bThemes = 1;
}
g_cxVScroll = GetSystemMetrics(SM_CXVSCROLL);
/* Setup fonts. */
- if (auto upLib = try_make_unique<Library>(TEXT("User32.dll"))) {
+ if (auto upLib = try_make<Library>(TEXT("User32.dll"))) {
if (upLib->GetProcAddress("SystemParametersInfo" WA)) {
NONCLIENTMETRICS m;
m.cbSize = sizeof(NONCLIENTMETRICS);
@@ -140,8 +140,8 @@ static LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam)
g_hWnd = (HWND)wParam;
/* Get DPI. */
- if (auto upLib = try_make_unique<Library>(TEXT("User32.dll")))
- if (auto GetDpiForWindow = (UINT (*)(HWND))upLib->GetProcAddress("GetDpiForWindow"))
+ if (auto opLib = try_make<Library>(TEXT("User32.dll")))
+ if (auto GetDpiForWindow = (UINT (*)(HWND))opLib->GetProcAddress("GetDpiForWindow"))
g_iDPI = GetDpiForWindow(g_hWnd);
/* Create child windows. */