Update docs

This commit is contained in:
Victor Zverovich 2018-05-20 17:10:34 -07:00
parent 2196025dd1
commit 6966db1dab
2 changed files with 33 additions and 44 deletions

View File

@ -164,6 +164,10 @@ Utilities
System errors System errors
------------- -------------
fmt does not use ``errno`` to communicate errors to the user, but it may call
system functions which set ``errno``. Users should not make any assumptions about
the value of ``errno`` being preserved by library functions.
.. doxygenclass:: fmt::system_error .. doxygenclass:: fmt::system_error
:members: :members:

View File

@ -2,8 +2,7 @@ Overview
======== ========
**fmt** (formerly cppformat) is an open-source formatting library. **fmt** (formerly cppformat) is an open-source formatting library.
It can be used as a safe alternative to printf or as a fast It can be used as a fast and safe alternative to printf and IOStreams.
alternative to C++ IOStreams.
.. raw:: html .. raw:: html
@ -30,9 +29,9 @@ in Python:
.. code:: c++ .. code:: c++
fmt::format("The answer is {}", 42); fmt::format("The answer is {}.", 42);
The ``fmt::format`` function returns a string "The answer is 42". You can use The ``fmt::format`` function returns a string "The answer is 42.". You can use
``fmt::memory_buffer`` to avoid constructing ``std::string``: ``fmt::memory_buffer`` to avoid constructing ``std::string``:
.. code:: c++ .. code:: c++
@ -94,19 +93,25 @@ Safety
------ ------
The library is fully type safe, automatic memory management prevents buffer The library is fully type safe, automatic memory management prevents buffer
overflow, errors in format strings are reported using exceptions. For example, overflow, errors in format strings are reported using exceptions or at compile
the code tim. For example, the code
.. code:: c++ .. code:: c++
fmt::format("The answer is {:d}", "forty-two"); fmt::format("The answer is {:d}", "forty-two");
throws a ``format_error`` exception with description throws a ``format_error`` exception with description "unknown format code 'd' for
"unknown format code 'd' for string", because the argument string", because the argument ``"forty-two"`` is a string while the format code
``"forty-two"`` is a string while the format code ``d`` ``d`` only applies to integers, while
only applies to integers.
Where possible, errors are caught at compile time. For example, the code .. code:: c++
format(fmt("The answer is {:d}"), "forty-two");
reports a compile-time error for the same reason on compilers that support
relaxed ``constexpr``.
The following code
.. code:: c++ .. code:: c++
@ -124,16 +129,10 @@ 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 what is
needed. needed.
Note that fmt does not use the value of the ``errno`` global to communicate
errors to the user, but it may call system functions which set ``errno``. Since
fmt does not attempt to preserve the value of ``errno``, users should not make
any assumptions about it and always set it to ``0`` before making any system
calls that convey error information via ``errno``.
Compact binary code Compact binary code
------------------- -------------------
Each call to a formatting function results in a compact binary code. For example The library is designed to produce compact per-call compiled code. For example
(`godbolt <https://godbolt.org/g/TZU4KF>`_), (`godbolt <https://godbolt.org/g/TZU4KF>`_),
.. code:: c++ .. code:: c++
@ -167,33 +166,19 @@ compiles to just
Portability Portability
----------- -----------
The library is highly portable. Here is an incomplete list of operating systems The library is highly portable and relies only on a small set of C++11 features:
and compilers where it has been tested and known to work:
* 64-bit (amd64) GNU/Linux with GCC 4.4.3, * variadic templates
`4.6.3 <https://travis-ci.org/fmtlib/fmt>`_, 4.7.2, 4.8.1, and Intel C++ * type traits
Compiler (ICC) 14.0.2 * rvalue references
* decltype
* trailing return types
* deleted functions
* 32-bit (i386) GNU/Linux with GCC 4.4.3, 4.6.3 These are available since GCC 4.4, Clang 2.9 and MSVC 18.0 (2013). For older
compilers use fmt `version 4.x
* Mac OS X with GCC 4.2.1 and Clang 4.2, 5.1.0 <https://github.com/fmtlib/fmt/releases/tag/4.1.0>`_ which continues to be
maintained and only requires C++98.
* 64-bit Windows with Visual C++ 2010, 2013 and
`2015 <https://ci.appveyor.com/project/vitaut/fmt>`_
* 32-bit Windows with Visual C++ 2010
Although the library uses C++11 features when available, it also works with
older compilers and standard library implementations. The only thing to keep in
mind for C++98 portability:
* Variadic templates: minimum GCC 4.4, Clang 2.9 or VS2013. This feature allows
the Format API to accept an unlimited number of arguments. With older
compilers the maximum is 15.
* User-defined literals: minimum GCC 4.7, Clang 3.1 or VS2015. The suffixes
``_format`` and ``_a`` are functionally equivalent to the functions
``fmt::format`` and ``fmt::arg``.
The output of all formatting functions is consistent across platforms. In The output of all formatting functions is consistent across platforms. In
particular, formatting a floating-point infinity always gives ``inf`` while the particular, formatting a floating-point infinity always gives ``inf`` while the
@ -211,7 +196,7 @@ Ease of Use
----------- -----------
fmt has a small self-contained code base with the core library consisting of fmt has a small self-contained code base with the core library consisting of
a single header file and a single source file and no external dependencies. just three header files and no external dependencies.
A permissive BSD `license <https://github.com/fmtlib/fmt#license>`_ allows A permissive BSD `license <https://github.com/fmtlib/fmt#license>`_ allows
using the library both in open-source and commercial projects. using the library both in open-source and commercial projects.