From 85a6d12a647a63e578260e942dec844d2f5ab66e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Fri, 15 Jul 2022 12:03:15 +0200 Subject: Use std::optional instead of std::unique_ptr for try_make. This requires C++17. --- c/defs.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'c/defs.h') 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 +#include #include #include #include @@ -144,15 +145,13 @@ inline int Dpi(int i) } template -std::unique_ptr try_make_unique(A ...args) +std::optional try_make(A ...args) { - std::unique_ptr up; try { - up = std::make_unique(args...); + return T(args...); } catch (...) { - up = nullptr; + return {}; } - return up; } #endif -- cgit v1.2.3