-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreport_fatal.hpp
51 lines (44 loc) · 1.11 KB
/
report_fatal.hpp
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//
// Copyright (c) 2021 Richard Hodges ([email protected])
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/madmongo1/blog-2021-10
//
#ifndef BLOG_OCT_2021_DEBUG_REPORT_FATAL_HPP
#define BLOG_OCT_2021_DEBUG_REPORT_FATAL_HPP
#include <iostream>
namespace debug
{
template<class Context>
struct fatal_reporter
{
Context context;
void operator()(std::exception_ptr ep, auto...args) const
{
std::cout << context << ": ";
try {
if (ep)
std::rethrow_exception(ep);
const char* sep = "";
auto emit = [&sep](auto&& arg)
{
std::cout << sep << arg;
sep = ", ";
};
(emit(args),...);
}
catch(std::exception& e)
{
std::cout << "exception: " << e.what() << "\n";
}
std::cout << "\n";
}
};
inline constexpr auto report_fatal(auto context)
{
return fatal_reporter<decltype(context)> { context };
}
}
#endif // BLOG_OCT_2021_DEBUG_REPORT_FATAL_HPP