6#include <boost/describe.hpp>
7#include <boost/describe/enum.hpp>
8#include <boost/describe/enumerators.hpp>
9#include <boost/mp11.hpp>
10#include <boost/pfr.hpp>
11#include <boost/type_index.hpp>
13#include <fmt/format.h>
14#include <range/v3/range/concepts.hpp>
22#include <source_location>
25#include <system_error>
30struct fmt::formatter<
std::exception> : formatter<std::string>
32 auto format(
const std::exception& from, fmt::format_context& ctx)
const {
33 std::string str = fmt::format(
"{}: '{}'", boost::typeindex::type_id_runtime(from).pretty_name(), from.what());
35 return formatter<std::string>::format(str, ctx);
40struct fmt::formatter<
std::filesystem::path> : formatter<std::string>
42 auto format(
const std::filesystem::path& from, fmt::format_context& ctx)
const {
43 return formatter<std::string>::format(from.string(), ctx);
48struct fmt::formatter<
std::timespec> : formatter<std::string>
50 auto format(
const std::timespec& from, fmt::format_context& ctx)
const {
51 return fmt::format_to(ctx.out(),
"timespec{{tv_sec={}, tv_nsec={}}}", from.tv_sec, from.tv_nsec);
56struct fmt::formatter<
std::source_location> : formatter<std::string>
58 auto format(
const std::source_location& from, fmt::format_context& ctx)
const {
59 return formatter<std::string>::format(
60 fmt::format(
"[{}@{}:{}:{}]", from.file_name(), from.line(), from.column(), from.function_name()), ctx);
73 auto format(
const std::error_code& from, format_context& ctx)
const {
74 return fmt::format_to(ctx.out(),
"{} : {}", strerrorname_np(from.value()), from.message());
81 auto format(
const std::optional<T>& from, format_context& ctx)
const {
83 return fmt::format_to(ctx.out(),
"nullopt");
86 if (is_debug_format) {
94template <
typename... Ts>
97 auto format(
const std::variant<Ts...>& from, format_context& ctx)
const {
98 const auto& [type_str, inner_str] = std::visit(
101 if constexpr (std::convertible_to<
decltype(val), std::string_view>) {
102 inner = fmt::format(
"{:?}", val);
106 return std::tuple{boost::typeindex::type_id<decltype(val)>().pretty_name(), inner};
110 if (is_debug_format) {
111 return fmt::format_to(ctx.out(),
"Variant<T={}>({})", type_str, inner_str);
114 return fmt::format_to(ctx.out(),
"{}", inner_str);
auto format_to_or_unknown(OutputIt &&out, T &&value, fmt::format_string< T > fmt="{}")
Definition unknown.hpp:29
std::string format_or_unknown(T &&value, fmt::format_string< T > fmt="{}")
Definition unknown.hpp:15
Definition byte_array.hpp:94