libmicroemu 0.2.0
ARM Microcontroller Emulator Library
Loading...
Searching...
No Matches
result.h File Reference

Contains the Result class which is used to return the result of a function. More...

#include "libmicroemu/status_code.h"
#include "libmicroemu/types.h"
#include <cstdlib>
#include <string_view>
#include <type_traits>

Go to the source code of this file.

Classes

struct  libmicroemu::internal::Result< T, TStatusCode >
 
struct  libmicroemu::internal::Result< void >
 

Namespaces

namespace  libmicroemu
 The libmicroemu namespace contains all classes and functions of the libmicroemu which are public.
 
namespace  libmicroemu::internal
 The libmicroemu::internal namespace contains all classes and functions of libmicroemu which are private.
 

Macros

#define TRY_ASSIGN(NAME, OUT_TYPE, CALL)
 Try to assign a value to a variable and return an error if the assignment fails.
 
#define TRY(OUT_TYPE, CALL)
 Try to call a function and return an error if the call fails.
 

Functions

template<typename T>
static constexpr Result< T > libmicroemu::internal::Ok (const T &content) noexcept
 
static constexpr Result< void > libmicroemu::internal::Ok () noexcept
 
template<typename T>
static constexpr Result< T > libmicroemu::internal::Err (const StatusCode &sc) noexcept
 
static constexpr Result< void > libmicroemu::internal::Err (const StatusCode &sc) noexcept
 
template<typename TIn, typename TRet>
static constexpr std::enable_if_t<!std::is_same_v< TRet, void >, Result< TRet > > libmicroemu::internal::Err (const Result< TIn > &res) noexcept
 
template<typename TIn, typename TRet>
static constexpr std::enable_if_t< std::is_same_v< TRet, void >, Result< TRet > > libmicroemu::internal::Err (const Result< TIn > &res) noexcept
 

Detailed Description

Contains the Result class which is used to return the result of a function.

Macro Definition Documentation

◆ TRY

#define TRY ( OUT_TYPE,
CALL )
Value:
{ \
auto r_tmp = CALL; \
if (r_tmp.IsErr()) { \
using t_ret_decl = decltype(CALL); \
using t_ret = typename t_ret_decl::Content; \
return Err<t_ret, OUT_TYPE>(r_tmp); \
}; \
}

Try to call a function and return an error if the call fails.

Parameters
OUT_TYPEThe type of the output
CALLThe call to make

◆ TRY_ASSIGN

#define TRY_ASSIGN ( NAME,
OUT_TYPE,
CALL )
Value:
auto r_##NAME = CALL; \
if (r_##NAME.IsErr()) { \
using t_ret_decl = decltype(CALL); \
using t_ret = typename t_ret_decl::Content; \
return Err<t_ret, OUT_TYPE>(r_##NAME); \
}; \
const auto &NAME = r_##NAME.content;

Try to assign a value to a variable and return an error if the assignment fails.

Parameters
NAMEThe name of the variable to assign
OUT_TYPEThe type of the output
CALLThe call to make to get the value