From 2ad86d28a5a46a082327ba84a636112b18101db0 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 10 Sep 2018 12:36:42 +1000 Subject: [PATCH] posix/except: add try_call --- posix/except.hpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/posix/except.hpp b/posix/except.hpp index ca59dc94..ec393748 100644 --- a/posix/except.hpp +++ b/posix/except.hpp @@ -7,9 +7,9 @@ * Danny Robson */ -#ifndef CRUFT_UTIL_POSIX_EXCEPT_HPP -#define CRUFT_UTIL_POSIX_EXCEPT_HPP +#pragma once +#include #include namespace cruft::posix { @@ -25,6 +25,18 @@ namespace cruft::posix { int code (void) const; static int last_code (void); + template + static auto + try_call (FunctionT &&func, Args&& ...args) + { + return try_value ( + std::invoke ( + std::forward (func), + std::forward (args)... + ) + ); + } + static void try_code (void); static void try_code (int code); @@ -67,5 +79,3 @@ namespace cruft::posix { int m_code; }; }; - -#endif