From d8f916a25ba953fabc29806fead2dd4a9e5d4d2d Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 14 Aug 2018 16:47:59 +1000 Subject: [PATCH] win32: add except::try_func --- win32/except.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/win32/except.hpp b/win32/except.hpp index 8cc160da..dde8ead2 100644 --- a/win32/except.hpp +++ b/win32/except.hpp @@ -11,6 +11,8 @@ #define CRUFT_UTIL_WIN32_EXCEPT_HPP #include +#include + #include namespace cruft::win32 { @@ -22,6 +24,18 @@ namespace cruft::win32 { DWORD code (void) const; static DWORD last_code (void); + template + static decltype(auto) + try_call (FunctionT &&func, ArgsT &&...args) + { + return try_value ( + std::invoke ( + std::forward (func), + std::forward (args)... + ) + ); + } + static HANDLE try_value (HANDLE); static void try_code (void);