-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.hpp
More file actions
30 lines (24 loc) · 843 Bytes
/
Copy patherror.hpp
File metadata and controls
30 lines (24 loc) · 843 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
#pragma once
#include <cstdio>
#include <expected>
#include <string>
namespace cfbox::base {
struct Error {
int code;
std::string 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