Skip to content

Commit

Permalink
Update example (fmtlib#2522)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut authored and PoetaKodu committed Nov 11, 2021
1 parent 20cd521 commit abe71ae
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ template and implement ``parse`` and ``format`` methods::

#include <fmt/format.h>

struct point { double x, y; };
struct point {
double x, y;
};

template <> struct fmt::formatter<point> {
// Presentation format: 'f' - fixed, 'e' - exponential.
Expand All @@ -210,8 +212,7 @@ template and implement ``parse`` and ``format`` methods::
if (it != end && (*it == 'f' || *it == 'e')) presentation = *it++;

// Check if reached the end of the range:
if (it != end && *it != '}')
throw format_error("invalid format");
if (it != end && *it != '}') throw format_error("invalid format");

// Return an iterator past the end of the parsed range:
return it;
Expand All @@ -222,10 +223,9 @@ template and implement ``parse`` and ``format`` methods::
template <typename FormatContext>
auto format(const point& p, FormatContext& ctx) -> decltype(ctx.out()) {
// ctx.out() is an output iterator to write to.
return format_to(
ctx.out(),
presentation == 'f' ? "({:.1f}, {:.1f})" : "({:.1e}, {:.1e})",
p.x, p.y);
return presentation == 'f'
? format_to(ctx.out(), "({:.1f}, {:.1f})", p.x, p.y)
: format_to(ctx.out(), "({:.1e}, {:.1e})", p.x, p.y);
}
};

Expand Down

0 comments on commit abe71ae

Please sign in to comment.