From 125bb0f19a4dce73fec1449b14342feb045d48f5 Mon Sep 17 00:00:00 2001 From: vitaut Date: Thu, 21 Apr 2016 06:50:54 -0700 Subject: [PATCH] Revise docs --- cppformat/format.h | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/cppformat/format.h b/cppformat/format.h index 46a03965..cd8b4e0f 100644 --- a/cppformat/format.h +++ b/cppformat/format.h @@ -1385,7 +1385,9 @@ class ArgList { /** \rst - An argument visitor. + An argument visitor based on the `curiously recurring template pattern + `_. + To use `~fmt::ArgVisitor` define a subclass that implements some or all of the visit methods with the same signatures as the methods in `~fmt::ArgVisitor`, for example, `visit_int(int)`. @@ -1403,9 +1405,6 @@ class ArgList { void visit_int(int value) { fmt::print("{}", value); } void visit_double(double value) { fmt::print("{}", value ); } }; - - `~fmt::ArgVisitor` uses the `curiously recurring template pattern - `_. \endrst */ template @@ -1918,7 +1917,9 @@ class PrintfFormatter : private FormatterBase { /** \rst - An argument formatter. + An argument formatter based on the `curiously recurring template pattern + `_. + To use `~fmt::BasicArgFormatter` define a subclass that implements some or all of the visit methods with the same signatures as the methods in `~fmt::ArgVisitor`, for example, `visit_int(int)`. @@ -1942,8 +1943,7 @@ class PrintfFormatter : private FormatterBase { : fmt::BasicArgFormatter(f, s, fmt) {} void visit_int(int value) { - fmt::FormatSpec &spec = this->spec(); - if (spec.type() == 'x') + if (spec().type() == 'x') visit_uint(value); // convert to unsigned and format else fmt::BasicArgFormatter::visit_int(value); @@ -1952,7 +1952,7 @@ class PrintfFormatter : private FormatterBase { std::string custom_format(const char *format_str, fmt::ArgList args) { fmt::MemoryWriter writer; - // Pass custom argument formatter to BasicFormatter. + // Pass custom argument formatter as a template arg to BasicFormatter. fmt::BasicFormatter formatter(args, writer); formatter.format(format_str); return writer.str(); @@ -1960,9 +1960,6 @@ class PrintfFormatter : private FormatterBase { FMT_VARIADIC(std::string, custom_format, const char *) std::string s = custom_format("{:x}", -42); // s == "ffffffd6" - - `~fmt::BasicArgFormatter` uses the `curiously recurring template pattern - `_. \endrst */ template @@ -1975,15 +1972,15 @@ class BasicArgFormatter : public internal::ArgFormatterBase { /** \rst Constructs an argument formatter object. - *f* is a reference to the main formatter object, *s* contains format - specifier information for standard argument types, and *fmt* points to - the part of the format string being parsed for custom argument types. + *formatter* is a reference to the main formatter object, *spec* contains + format specifier information for standard argument types, and *fmt* points + to the part of the format string being parsed for custom argument types. \endrst */ - BasicArgFormatter(BasicFormatter &f, - FormatSpec &s, const Char *fmt) - : internal::ArgFormatterBase(f.writer(), s), - formatter_(f), format_(fmt) {} + BasicArgFormatter(BasicFormatter &formatter, + FormatSpec &spec, const Char *fmt) + : internal::ArgFormatterBase(formatter.writer(), spec), + formatter_(formatter), format_(fmt) {} /** Formats argument of a custom (user-defined) type. */ void visit_custom(internal::Arg::CustomValue c) { @@ -1996,8 +1993,9 @@ template class ArgFormatter : public BasicArgFormatter, Char> { public: /** Constructs an argument formatter object. */ - ArgFormatter(BasicFormatter &f, FormatSpec &s, const Char *fmt) - : BasicArgFormatter, Char>(f, s, fmt) {} + ArgFormatter(BasicFormatter &formatter, + FormatSpec &spec, const Char *fmt) + : BasicArgFormatter, Char>(formatter, spec, fmt) {} }; /** This template formats data and writes the output to a writer. */