#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__} *