aboutsummaryrefslogtreecommitdiff
path: root/c/defs.h
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/defs.h
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/defs.h')
-rw-r--r--c/defs.h9
1 files changed, 4 insertions, 5 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