【发布时间】:2020-08-25 13:14:26
【问题描述】:
我想知道向fmt::formatter::format 添加一些任意文本的正确方法是什么。基本上,我想为我的对象命名。当前的实现有效,但我不确定它是否可以做得更好,而且我觉得我的垂直对齐技巧可以做得更好。
namespace fmt {
template <>
struct formatter<Experiment> {
constexpr auto parse(format_parse_context& ctx) {
return ctx.begin();
}
template <typename FormatContext>
auto format(const Experiment& e, FormatContext& ctx) {
ctx.out() = format_to(ctx.out(), "Experiment:\n\t\t\t\t");
return format_to(ctx.out(),
"{}", join(e.begin(), e.end(), "\n\t\t\t\t"));
}
};
}
【问题讨论】: