posix/except: add try_call

This commit is contained in:
Danny Robson 2018-09-10 12:36:42 +10:00
parent 4fd20d2acf
commit 2ad86d28a5

View File

@ -7,9 +7,9 @@
* Danny Robson <danny@nerdcruft.net> * Danny Robson <danny@nerdcruft.net>
*/ */
#ifndef CRUFT_UTIL_POSIX_EXCEPT_HPP #pragma once
#define CRUFT_UTIL_POSIX_EXCEPT_HPP
#include <functional>
#include <stdexcept> #include <stdexcept>
namespace cruft::posix { namespace cruft::posix {
@ -25,6 +25,18 @@ namespace cruft::posix {
int code (void) const; int code (void) const;
static int last_code (void); static int last_code (void);
template <typename FunctionT, typename ...Args>
static auto
try_call (FunctionT &&func, Args&& ...args)
{
return try_value (
std::invoke (
std::forward<FunctionT> (func),
std::forward<Args> (args)...
)
);
}
static void try_code (void); static void try_code (void);
static void try_code (int code); static void try_code (int code);
@ -67,5 +79,3 @@ namespace cruft::posix {
int m_code; int m_code;
}; };
}; };
#endif