5#include <boost/describe.hpp>
6#include <boost/describe/enum.hpp>
7#include <boost/describe/enumerators.hpp>
8#include <boost/mp11.hpp>
9#include <boost/pfr.hpp>
10#include <boost/type_index.hpp>
12#include <fmt/format.h>
13#include <range/v3/range/concepts.hpp>
21#include <source_location>
24#include <system_error>
29struct fmt::formatter<std::exception> : formatter<std::string>
31 auto format(
const std::exception& from, fmt::format_context& ctx)
const {
32 std::string str = fmt::format(
"{}: '{}'", boost::typeindex::type_id_runtime(from).pretty_name(), from.what());
34 return formatter<std::string>::format(str, ctx);
39struct fmt::formatter<std::filesystem::path> : formatter<std::string>
41 auto format(
const std::filesystem::path& from, fmt::format_context& ctx)
const {
42 return formatter<std::string>::format(from.string(), ctx);
47struct fmt::formatter<std::timespec> : formatter<std::string>
49 auto format(
const std::timespec& from, fmt::format_context& ctx)
const {
50 return format_to(ctx.out(),
"timespec{{tv_sec={}, tv_nsec={}}}", from.tv_sec, from.tv_nsec);
55struct fmt::formatter<std::source_location> : formatter<std::string>
57 auto format(
const std::source_location& from, fmt::format_context& ctx)
const {
58 return formatter<std::string>::format(
59 fmt::format(
"[{}@{}:{}:{}]", from.file_name(), from.line(), from.column(), from.function_name()), ctx);
72 auto format(
const std::error_code& from, format_context& ctx)
const {
73 return format_to(ctx.out(),
"{} : {}", strerrorname_np(from.value()), from.message());
80 auto format(
const std::optional<T>& from, format_context& ctx)
const {
82 return fmt::format_to(ctx.out(),
"nullopt");
85 if (is_debug_format) {
86 return fmt::format_to(ctx.out(),
"Optional({})", from.value());
89 return fmt::format_to(ctx.out(),
"{}", from.value());
93template <
typename... Ts>
96 auto format(
const std::variant<Ts...>& from, format_context& ctx)
const {
97 const auto& [type_str, inner_str] = std::visit(
100 if constexpr (std::convertible_to<
decltype(val), std::string_view>) {
101 inner = fmt::format(
"{:?}", val);
103 inner = fmt::format(
"{}", val);
105 return std::tuple{boost::typeindex::type_id<decltype(val)>().pretty_name(), inner};
109 if (is_debug_format) {
110 return fmt::format_to(ctx.out(),
"Variant<T={}>({})", type_str, inner_str);
113 return fmt::format_to(ctx.out(),
"{}", inner_str);