3#include <source_location>
11 template<
typename... Args>
12 inline void error_internal(
const char* preamble, std::format_string<Args...> fmt,
const std::source_location& loc, Args&&... args)
14 std::fprintf(stderr,
"%s", preamble);
15 std::fprintf(stderr,
"%s", std::format(fmt, std::forward<Args>(args)...).c_str());
17 std::string diag_info = std::format(
"\n\tIn file {}({},{})\n\t>\t{}", loc.file_name(), loc.line(), loc.column(), loc.function_name());
19 std::fprintf(stderr,
"%s", diag_info.c_str());
34#define tz_assert(cond, fmt, ...) if(!(cond)){tz::detail::error_internal("[Assertion Fail]: ", fmt, std::source_location::current(), __VA_ARGS__);}
43#define tz_error(fmt, ...) tz::detail::error_internal("[Error]: ", fmt, std::source_location::current(), __VA_ARGS__)
46#define tz_seterror(errcode, msg) set_last_error(std::format("({}): {}", error_code_name(errcode), msg))
66#define tz_must(fnret) [sl = std::source_location::current()](auto ret){if constexpr(std::is_same_v<std::decay_t<decltype(ret)>, tz::error_code>){if(ret != tz::error_code::success){tz::detail::error_internal("[Must Failure]: ", "error {} {}", sl, static_cast<int>(ret), tz::last_error());}} else{if(!ret.has_value()){tz::detail::error_internal("[Must Failure]: ", "error {} {}", sl, static_cast<int>(ret.error()), tz::last_error());} return ret.value();}}(fnret)
69#define UNERR(errcode, preamble, ...) {auto msg = std::format(preamble, __VA_ARGS__); tz_seterror(errcode, msg); return std::unexpected(errcode);}
70#define RETERR(errcode, preamble, ...){auto msg = std::format(preamble, __VA_ARGS__); tz_seterror(errcode, msg); return errcode;}