From 1bb484e1c41367bd015dcc59bcaff5e6c6e93c2f Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Tue, 17 Mar 2020 15:26:53 +0100 Subject: [PATCH] "Grammar" chapter refactored and "Default formatting" chapter added --- docs/framework/text_output.rst | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/docs/framework/text_output.rst b/docs/framework/text_output.rst index 28f125c9..e2ea6a5a 100644 --- a/docs/framework/text_output.rst +++ b/docs/framework/text_output.rst @@ -32,15 +32,28 @@ of an unknown ``auto`` type before passing it to the text output:: Formatting the output --------------------- -Grammar: -^^^^^^^^ +Grammar +^^^^^^^ .. productionlist:: - units-format-spec: fill-and-align[opt] sign[opt] width[opt] precision[opt] type[opt] units-specs[opt] + units-format-spec: [fill-and-align] [sign] [width] [precision] [type] [units-specs] units-specs: conversion-spec : units-specs conversion-spec : units-specs literal-char literal-char: any character other than '{' or '}' - conversion-spec: '%' modifier[opt] units-type + conversion-spec: '%' [modifier] units-type modifier: 'A' units-type: one of 'n', 'q', 'Q', 't', '%' + + +Default formatting +^^^^^^^^^^^^^^^^^^ + +To format `quantity` values the formatting facility uses :token:`units-format-spec`. +In case it is left empty the default formatting of ``{:%Q %q}`` is applied. The same +default formatting is also applied to output streams. This is why the following lines +produce the same output:: + + std::cout << "Distance: " << 123q_km << "\n"; + fmt::print("Distance: {}\n", 123q_km); + fmt::print("Distance: {:%Q %q}\n", 123q_km);