MGIS
Loading...
Searching...
No Matches
Invoke.hxx File Reference

This header declares the invoke function to call function objects that may throw exceptions. More...

#include <optional>
#include <functional>
#include <type_traits>
#include "MGIS/Config.hxx"
#include "MGIS/InvalidResult.hxx"
#include "MGIS/Context.hxx"
#include "MGIS/Utilities/Invoke.ixx"

Namespaces

namespace  mgis
 the namespace mgis encloses all the MGIS project.
 

Macros

#define MGIS_INVOKE(e, ...)   ::mgis::invoke(e, __VA_ARGS__)
 a simple wrapper around the invoke function which handles the declaration of the source location if needed
 
#define MGIS_INVOKE_CHECK_ERRNO(e, ...)   ::mgis::invokeCheckErrno(e, __VA_ARGS__)
 
#define MGIS_TRY_INVOKE_VOID(e, ...)
 a simple wrapper around the invoke function when the returned type of the callable is void
 
#define MGIS_TRY_INVOKE_VOID_CHECK_ERRNO(e, ...)
 
#define MGIS_TRY_INVOKE(v, e, ...)
 a simple wrapper around the invoke function
 
#define MGIS_TRY_INVOKE_CHECK_ERRNO(v, e, ...)
 

Typedefs

template<typename F , typename... ArgumentsTypes>
using mgis::invoke_result_t = std::conditional_t< std::is_void_v< std::invoke_result_t< F, ArgumentsTypes... > >, bool, std::optional< std::invoke_result_t< F, ArgumentsTypes... > > >
 a simple alias
 

Functions

template<typename F , typename... ArgumentsTypes>
invoke_result_t< F, ArgumentsTypes... > mgis::invoke (Context &, F &&, ArgumentsTypes &&...) noexcept
 invoke the given callable object param[inout] ctx: execution context
 
template<typename F , typename... ArgumentsTypes>
invoke_result_t< F, ArgumentsTypes... > mgis::invokeCheckErrno (Context &, F &&, ArgumentsTypes &&...) noexcept
 

Detailed Description

This header declares the invoke function to call function objects that may throw exceptions.

Date
07/11/2022

Macro Definition Documentation

◆ MGIS_INVOKE

#define MGIS_INVOKE (   e,
  ... 
)    ::mgis::invoke(e, __VA_ARGS__)

a simple wrapper around the invoke function which handles the declaration of the source location if needed

Parameters
[in,out]ctxexecution context
Warning
If the function invoked has optional arguments (with default values), all the optional arguments must be provided, else the code will not compile with an obscure error message
Note
a version check the errno value while the other don't (names are self descriptive)

◆ MGIS_TRY_INVOKE

#define MGIS_TRY_INVOKE (   v,
  e,
  ... 
)
Value:
const auto MGIS_TEMPORARY_VARIABLE(v) = MGIS_INVOKE(e, __VA_ARGS__); \
if (!MGIS_TEMPORARY_VARIABLE(v).hasValue()) { \
return InvalidResult{}; \
} \
auto &v = *(MGIS_TEMPORARY_VARIABLE(v));
#define MGIS_INVOKE(e,...)
a simple wrapper around the invoke function which handles the declaration of the source location if n...
Definition Invoke.hxx:35

a simple wrapper around the invoke function

Parameters
[in,out]ctxexecution context
[out]vvariable name which will contain the returned value of the function invoked. This variable is declared inside the macro and so must not be declared before.
Warning
If the function invoked has optional arguments (with default values), all the optional arguments must be provided, else the code will not compile with an obscure error message
Note
a version check the errno value while the other don't (names are self descriptive)

◆ MGIS_TRY_INVOKE_CHECK_ERRNO

#define MGIS_TRY_INVOKE_CHECK_ERRNO (   v,
  e,
  ... 
)
Value:
const auto MGIS_TEMPORARY_VARIABLE(v) = \
MGIS_INVOKE_CHECK_ERRNO(e, __VA_ARGS__); \
if (!MGIS_TEMPORARY_VARIABLE(v).hasValue()) { \
return InvalidResult{}; \
} \
auto &v = *(MGIS_TEMPORARY_VARIABLE(v));

◆ MGIS_TRY_INVOKE_VOID

#define MGIS_TRY_INVOKE_VOID (   e,
  ... 
)
Value:
if (!MGIS_INVOKE(e, __VA_ARGS__)) { \
return InvalidResult{}; \
}

a simple wrapper around the invoke function when the returned type of the callable is void

Parameters
[in,out]ctxexecution context
Warning
If the function invoked has optional arguments (with default values), all the optional arguments must be provided, else the code will not compile with an obscure error message
Note
a version check the errno value while the other don't (names are self descriptive)

◆ MGIS_TRY_INVOKE_VOID_CHECK_ERRNO

#define MGIS_TRY_INVOKE_VOID_CHECK_ERRNO (   e,
  ... 
)
Value:
if (!MGIS_INVOKE_CHECK_ERRNO(e, __VA_ARGS__)) { \
return InvalidResult{}; \
}