Update docs

This commit is contained in:
Victor Zverovich 2020-09-30 17:38:28 -07:00
parent 4d0aa4d8fe
commit 05a28312cf
2 changed files with 23 additions and 25 deletions

View File

@ -17,8 +17,8 @@
:alt: Ask questions at StackOverflow with the tag fmt :alt: Ask questions at StackOverflow with the tag fmt
:target: https://stackoverflow.com/questions/tagged/fmt :target: https://stackoverflow.com/questions/tagged/fmt
**{fmt}** is an open-source formatting library for C++. **{fmt}** is an open-source formatting library providing a fast and safe
It can be used as a safe and fast alternative to (s)printf and iostreams. alternative to C stdio and C++ iostreams.
If you like this project, please consider donating to BYSOL, If you like this project, please consider donating to BYSOL,
an initiative to help victims of political repressions in Belarus: an initiative to help victims of political repressions in Belarus:

View File

@ -48,21 +48,19 @@ The ``fmt::print`` function performs formatting and writes the result to a strea
fmt::print(stderr, "System error code = {}\n", errno); fmt::print(stderr, "System error code = {}\n", errno);
The file argument can be omitted in which case the function prints to If you omit the file argument the function will print to ``stdout``:
``stdout``:
.. code:: c++ .. code:: c++
fmt::print("Don't {}\n", "panic"); fmt::print("Don't {}\n", "panic");
The Format API also supports positional arguments useful for localization: The format API also supports positional arguments useful for localization:
.. code:: c++ .. code:: c++
fmt::print("I'd rather be {1} than {0}.", "right", "happy"); fmt::print("I'd rather be {1} than {0}.", "right", "happy");
Named arguments can be created with ``fmt::arg``. This makes it easier to track You can pass named arguments with ``fmt::arg``:
what goes where when multiple arguments are being formatted:
.. code:: c++ .. code:: c++
@ -91,16 +89,17 @@ time. For example, the code
fmt::format("The answer is {:d}", "forty-two"); fmt::format("The answer is {:d}", "forty-two");
throws a ``format_error`` exception with description "unknown format code 'd' for throws the ``format_error`` exception because the argument ``"forty-two"`` is a
string", because the argument ``"forty-two"`` is a string while the format code string while the format code ``d`` only applies to integers.
``d`` only applies to integers, while
The code
.. code:: c++ .. code:: c++
format(FMT_STRING("The answer is {:d}"), "forty-two"); format(FMT_STRING("The answer is {:d}"), "forty-two");
reports a compile-time error for the same reason on compilers that support reports a compile-time error on compilers that support relaxed ``constexpr``.
relaxed ``constexpr``. See `here <api.html#c.fmt>`_ for details. See `here <api.html#c.fmt>`_ for details.
The following code The following code
@ -117,13 +116,13 @@ formatted into a narrow string. You can use a wide format string instead:
For comparison, writing a wide character to ``std::ostream`` results in For comparison, writing a wide character to ``std::ostream`` results in
its numeric value being written to the stream (i.e. 1070 instead of letter 'ю' its numeric value being written to the stream (i.e. 1070 instead of letter 'ю'
which is represented by ``L'\x42e'`` if we use Unicode) which is rarely what is which is represented by ``L'\x42e'`` if we use Unicode) which is rarely
needed. desirable.
Compact Binary Code Compact Binary Code
------------------- -------------------
The library is designed to produce compact per-call compiled code. For example The library produces compact per-call compiled code. For example
(`godbolt <https://godbolt.org/g/TZU4KF>`_), (`godbolt <https://godbolt.org/g/TZU4KF>`_),
.. code:: c++ .. code:: c++
@ -144,8 +143,8 @@ compiles to just
mov rcx, rsp mov rcx, rsp
mov edi, offset .L.str mov edi, offset .L.str
mov esi, 17 mov esi, 17
mov edx, 2 mov edx, 1
call fmt::v5::vprint(fmt::v5::basic_string_view<char>, fmt::v5::format_args) call fmt::v7::vprint(fmt::v7::basic_string_view<char>, fmt::v7::format_args)
xor eax, eax xor eax, eax
add rsp, 24 add rsp, 24
ret ret
@ -167,20 +166,19 @@ The library is highly portable and relies only on a small set of C++11 features:
* deleted functions * deleted functions
* alias templates * alias templates
These are available since GCC 4.8, Clang 3.0 and MSVC 19.0 (2015). For older These are available in GCC 4.8, Clang 3.0, MSVC 19.0 (2015) and more recent
compilers use {fmt} `version 4.x compiler version. For older compilers use {fmt} `version 4.x
<https://github.com/fmtlib/fmt/releases/tag/4.1.0>`_ which continues to be <https://github.com/fmtlib/fmt/releases/tag/4.1.0>`_ which is maintained and
maintained and only requires C++98. only requires C++98.
The output of all formatting functions is consistent across platforms. In The output of all formatting functions is consistent across platforms.
particular, formatting a floating-point infinity always gives ``inf`` while the For example,
output of ``printf`` is platform-dependent. For example,
.. code:: .. code::
fmt::print("{}", std::numeric_limits<double>::infinity()); fmt::print("{}", std::numeric_limits<double>::infinity());
always prints ``inf``. always prints ``inf`` while the output of ``printf`` is platform-dependent.
.. _ease-of-use: .. _ease-of-use: