3#include <sysio/vm/config.hpp>
8# include <boost/system/error_code.hpp>
9# include <boost/type_traits.hpp>
12# define ERROR_CODE_NAMESPACE boost::system
13# define TRUE_TYPE boost::true_type
15# include <system_error>
16# include <type_traits>
19# define ERROR_CODE_NAMESPACE std
20# define TRUE_TYPE std::true_type
23#define GENERATE_ERROR_CATEGORY(CATEGORY, NAME) \
24 namespace sysio { namespace vm { \
25 struct CATEGORY##_category : error_category_t { \
26 const char* name() const noexcept override { return #NAME; } \
27 std::string message(int ev) const override; \
29 const CATEGORY##_category __##CATEGORY##_category{}; \
30 template <typename T> \
31 static inline constexpr auto is_a(const error_code_t& ec) \
32 -> std::enable_if_t<std::is_same_v<T, CATEGORY##_category>, bool> { \
33 return ec.category() == __##CATEGORY##_category; \
38#define GENERATE_ENUM_ELEM(PARENT, ITEM) ITEM,
40#define GENERATE_STR_ELEM(PARENT, ITEM) \
44#define CREATE_ERROR_CODES(CATEGORY, ERRORS) \
45 namespace sysio { namespace vm { \
46 enum class CATEGORY { ERRORS(GENERATE_ENUM_ELEM) }; \
49 namespace ERROR_CODE_NAMESPACE { \
51 struct is_error_code_enum<sysio::vm::CATEGORY> : TRUE_TYPE {}; \
53 namespace sysio { namespace vm { \
54 inline std::string CATEGORY##_category::message(int ev) const { \
55 switch (static_cast<CATEGORY>(ev)) { ERRORS(GENERATE_STR_ELEM) } \
58 inline error_code_t make_error_code(CATEGORY e) noexcept { \
59 return { static_cast<int>(e), __##CATEGORY##_category }; \
std::error_code error_code_t
std::error_category error_category_t