The accepted answer does not work anymore with newer versions of spdlog, fmt
now requires specializing formatter<T>
(see https://fmt.dev/latest/api.html#udt for details).
Using your p
struct this is the formatter:
#include <spdlog/fmt/bundled/format.h>
template<>
struct fmt::formatter<p> {
constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) {
return ctx.end();
}
template <typename FormatContext>
auto format(const p& input, FormatContext& ctx) -> decltype(ctx.out()) {
return format_to(ctx.out(),
"(x={}, y={}, z={})",
input.x, input.y, input.z);
}
};
The parse
method is used to read eventual format specifications, if you don't need them you can simply return ctx.end()
and skip specifications like in the sample.