Tweak the docs

This commit is contained in:
Victor Zverovich 2019-11-17 10:10:32 -08:00
parent c01ec54fde
commit 080b6899d2

View File

@ -124,11 +124,11 @@ template and implement ``parse`` and ``format`` methods::
// fmt::format("{:f} - point of interest", point{1, 2}); // fmt::format("{:f} - point of interest", point{1, 2});
// //
// the range will contain "f} - point of interest". The formatter should // the range will contain "f} - point of interest". The formatter should
// parse specifiers until '}' or the end of the range. In this example, // parse specifiers until '}' or the end of the range. In this example
// the formatter should parse the 'f' specifier and return an iterator // the formatter should parse the 'f' specifier and return an iterator
// pointing to '}'. // pointing to '}'.
// Parse presentation format and store the parse result in the formatter: // Parse the presentation format and store it in the formatter:
auto it = ctx.begin(), end = ctx.end(); auto it = ctx.begin(), end = ctx.end();
if (it != end && (*it == 'f' || *it == 'e')) presentation = *it++; if (it != end && (*it == 'f' || *it == 'e')) presentation = *it++;
@ -140,10 +140,11 @@ template and implement ``parse`` and ``format`` methods::
return it; return it;
} }
// Formats the point p using parsed format specification (presentation) // Formats the point p using the parsed format specification (presentation)
// stored in this formatter. // stored in this formatter.
template <typename FormatContext> template <typename FormatContext>
auto format(const point& p, FormatContext& ctx) { auto format(const point& p, FormatContext& ctx) {
// ctx.out() is an output iterator to write to.
return format_to( return format_to(
ctx.out(), ctx.out(),
presentation == 'f' ? "({:.1f}, {:.1f})" : "({:.1e}, {:.1e})", presentation == 'f' ? "({:.1f}, {:.1f})" : "({:.1e}, {:.1e})",