【发布时间】:2019-10-04 03:42:35
【问题描述】:
在格式化我自己的自定义类型时,我将如何允许自定义填充等?
struct S
{
int x;
};
template<> struct fmt::formatter<S> {
template <typename ParseContext>
constexpr auto parse(ParseContext& ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const S& s, FormatContext& ctx)
{
return format_to(ctx.out(), "{}", s.x);
}
};
S s; s.x = 1;
fmt::format("{:<10}", s); // error
【问题讨论】: