Stax
Programming language
Loading...
Searching...
No Matches
result.hpp File Reference
#include <boost/describe.hpp>
#include <boost/describe/enum_to_string.hpp>
#include <boost/outcome.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/stringize.hpp>
#include <filesystem>
#include <optional>
#include <string>
#include <system_error>
#include "utils.hpp"
Include dependency graph for result.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  stax::result::is_error_enum< T >
 
class  stax::result::Err
 

Namespaces

namespace  stax
 
namespace  stax::result
 

Concepts

concept  stax::result::IsErrorCode
 

Macros

#define DEFINE_ERROR_IMPL(module_name, ERROR_ENUM)
 
#define DEFINE_ERROR(module_name, name, ...)
 
#define RESULT_UNIQUE_NAME()   BOOST_PP_CAT(__result_, __COUNTER__)
 
#define TRY_RESULT(...)   BOOST_OUTCOME_TRY(__VA_ARGS__)
 
#define TRY_RESULT_IMPL(unique_name, expr, alt)
 
#define TRY_RESULT_OR(expr, alt)    TRY_RESULT_IMPL(RESULT_UNIQUE_NAME(), expr, alt)
 

Typedefs

template<typename T >
using stax::result_t
 

Functions

auto stax::result::Ok ()
 

Macro Definition Documentation

◆ DEFINE_ERROR

#define DEFINE_ERROR ( module_name,
name,
... )
Value:
BOOST_DEFINE_ENUM_CLASS(name, __VA_ARGS__) \
DEFINE_ERROR_IMPL(module_name, name)

◆ DEFINE_ERROR_IMPL

#define DEFINE_ERROR_IMPL ( module_name,
ERROR_ENUM )
Value:
class ERROR_ENUM##_category_t : public std::error_category { \
public: \
const char* name() const noexcept override { \
return (module_name BOOST_PP_STRINGIZE(_##ERROR_ENUM)); \
} \
std::string message(int32_t e) const override { \
const auto ec = static_cast<ERROR_ENUM>(e); \
return boost::describe::enum_to_string(ec, ""); \
} \
}; \
inline auto ERROR_ENUM##_category()->const ERROR_ENUM##_category_t& { \
static const ERROR_ENUM##_category_t e_cat{}; \
return e_cat; \
} \
inline auto make_error_code(ERROR_ENUM ec) -> std::error_code { \
return {static_cast<int32_t>(ec), ERROR_ENUM##_category()}; \
}

◆ RESULT_UNIQUE_NAME

#define RESULT_UNIQUE_NAME ( )    BOOST_PP_CAT(__result_, __COUNTER__)

◆ TRY_RESULT

#define TRY_RESULT ( ...)    BOOST_OUTCOME_TRY(__VA_ARGS__)

◆ TRY_RESULT_IMPL

#define TRY_RESULT_IMPL ( unique_name,
expr,
alt )
Value:
auto unique_name = expr; \
alt

◆ TRY_RESULT_OR

#define TRY_RESULT_OR ( expr,
alt )    TRY_RESULT_IMPL(RESULT_UNIQUE_NAME(), expr, alt)