From 4809e2956a9ec04e97f026c5df224349f61179b0 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 6 Oct 2016 07:38:19 -0700 Subject: [PATCH] Minor documentation changes --- doc/api.rst | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/doc/api.rst b/doc/api.rst index 769284cf..5a93b4aa 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -58,29 +58,26 @@ formatting:: The format string syntax is described in the documentation of `strftime `_. -Formatting User-Defined types +Formatting user-defined types ----------------------------- -A custom ``format_arg`` function may be implemented and used to format any user- -defined type. That is how date and time formatting described in the previous -section is implemented in :file:`fmt/time.h`. The following example shows how to implement custom formatting for a user-defined structure. +A custom ``format_arg`` function may be implemented and used to format any +user-defined type. That is how date and time formatting described in the +previous section is implemented in :file:`fmt/time.h`. The following example +shows how to implement custom formatting for a user-defined structure. :: - struct MyStruct { double a, b, c, d; }; + struct MyStruct { double a, b; }; void format_arg(fmt::BasicFormatter &f, - const char *&format_str, const MyStruct &s) { - f.writer().write("[MyStruct: a={:.1f}, b={:.2f}, c={:.3f}, d={:.4f}]", - s.a, s.b, s.c, s.d); + const char *&format_str, const MyStruct &s) { + f.writer().write("[MyStruct: a={:.1f}, b={:.2f}]", s.a, s.b); } - void f() - { - MyStruct m = { 1, 2, 3, 4 }; - std::string s = fmt::format("m={}", n); - // s == "m=[MyStruct: a=1.0, b=2.00, c=3.000, d=4.0000]" - } + MyStruct m = { 1, 2 }; + std::string s = fmt::format("m={}", n); + // s == "m=[MyStruct: a=1.0, b=2.00]" Note in the example above the ``format_arg`` function ignores the contents of ``format_str`` so the type will always be formatted as specified. See