diff options
author | John Ankarström <john@ankarstrom.se> | 2022-07-15 12:03:15 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-07-15 12:03:15 +0200 |
commit | 85a6d12a647a63e578260e942dec844d2f5ab66e (patch) | |
tree | fef16cfbec2abc8a6b6c837dd9d5cf938bcd749c /c/defs.h | |
parent | 7153a258427d3e401914de800bfdf1c7165cab71 (diff) | |
download | EpisodeBrowser-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.h | 9 |
1 files changed, 4 insertions, 5 deletions
@@ -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 |