-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.hpp
More file actions
36 lines (29 loc) · 929 Bytes
/
error.hpp
File metadata and controls
36 lines (29 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#pragma once
#include <cstdio>
#include <expected>
#include <string>
#include <string_view>
namespace cfbox::base {
struct Error {
int code;
std::string msg;
};
struct ErrorView {
int code;
std::string_view msg;
};
template <typename T> using Result = std::expected<T, Error>;
} // namespace cfbox::base
#ifndef CFBOX_ERR
# define CFBOX_ERR(cmd, fmt, ...) \
std::fprintf(stderr, "cfbox " cmd ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__)
# define CFBOX_ERR_V(cmd, fmt, ...) \
std::fprintf(stderr, "cfbox %s: " fmt "\n", cmd __VA_OPT__(,) __VA_ARGS__)
#endif
#ifndef CFBOX_TRY
# define CFBOX_TRY(var, expr) \
auto var = (expr); \
if (!var) { \
return std::unexpected(std::move(var).error()); \
}
#endif