undef throw struct throw_dummy constexpr throw_dummy size_t line char

 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
#undef throw
struct throw_dummy {
constexpr throw_dummy(size_t line, char const *filename)
: line {line}, filename {filename} {}
size_t line;
char const *filename;
};
template <typename E>
struct ExceptionWithInfo : public E {
ExceptionWithInfo(size_t line, char const *filename, E &&e)
: E { std::move(e) }, line {line}, filename {filename}
{
info = fmt::sprintf("%s:%d: %s: %s", filename, line, cxxDemangle(typeid(E).name()), E::what());
}
~ExceptionWithInfo() final = default;
virtual const char *what() const noexcept {
return info.data();
}
size_t line;
char const *filename;
std::string info;
};
#define ____THROW_(LINE) ____zz_throw_dummy##LINE
#define ____THROW(LINE) ____THROW_(LINE)
template <class F>
[[noreturn]] inline void
operator*(throw_dummy &&d, F &&f) {
throw ExceptionWithInfo<F>(d.line, d.filename, std::forward<F>(f));
}
#define throw throw_dummy{__LINE__, __FILENAME__} *