Merge branch 'develop' into collected-small-changes
This commit is contained in:
@ -300,18 +300,19 @@ Formatting with the {fmt} library
|
||||
|
||||
The LAMMPS source code includes a copy of the `{fmt} library
|
||||
<https://fmt.dev>`_, which is preferred over formatting with the
|
||||
"printf()" family of functions. The primary reason is that it allows
|
||||
a typesafe default format for any type of supported data. This is
|
||||
"printf()" family of functions. The primary reason is that it allows a
|
||||
typesafe default format for any type of supported data. This is
|
||||
particularly useful for formatting integers of a given size (32-bit or
|
||||
64-bit) which may require different format strings depending on
|
||||
compile time settings or compilers/operating systems. Furthermore,
|
||||
{fmt} gives better performance, has more functionality, a familiar
|
||||
formatting syntax that has similarities to ``format()`` in Python, and
|
||||
provides a facility that can be used to integrate format strings and a
|
||||
variable number of arguments into custom functions in a much simpler
|
||||
way than the varargs mechanism of the C library. Finally, {fmt} has
|
||||
been included into the C++20 language standard, so changes to adopt it
|
||||
are future-proof.
|
||||
64-bit) which may require different format strings depending on compile
|
||||
time settings or compilers/operating systems. Furthermore, {fmt} gives
|
||||
better performance, has more functionality, a familiar formatting syntax
|
||||
that has similarities to ``format()`` in Python, and provides a facility
|
||||
that can be used to integrate format strings and a variable number of
|
||||
arguments into custom functions in a much simpler way than the varargs
|
||||
mechanism of the C library. Finally, {fmt} has been included into the
|
||||
C++20 language standard as ``std::format()``, so changes to adopt it are
|
||||
future-proof, for as long as they are not using any extensions that are
|
||||
not (yet) included into C++.
|
||||
|
||||
The long-term plan is to switch to using ``std::format()`` instead of
|
||||
``fmt::format()`` when the minimum C++ standard required for LAMMPS will
|
||||
@ -324,11 +325,13 @@ Formatted strings are frequently created by calling the
|
||||
``printf()``, the {fmt} library uses ``{}`` to embed format descriptors.
|
||||
In the simplest case, no additional characters are needed, as {fmt} will
|
||||
choose the default format based on the data type of the argument.
|
||||
Otherwise, the ``fmt::print()`` function may be used instead of
|
||||
``printf()`` or ``fprintf()``. In addition, several LAMMPS output
|
||||
functions, that originally accepted a single string as argument have
|
||||
been overloaded to accept a format string with optional arguments as
|
||||
well (e.g., ``Error::all()``, ``Error::one()``, ``utils::logmesg()``).
|
||||
Otherwise, the :cpp:func:`utils::print() <LAMMPS_NS::utils::print>`
|
||||
function may be used instead of ``printf()`` or ``fprintf()``. In
|
||||
addition, several LAMMPS output functions, that originally accepted a
|
||||
single string as argument have been overloaded to accept a format string
|
||||
with optional arguments as well (e.g., ``Error::all()``,
|
||||
``Error::one()``, :cpp:func:`utils::logmesg()
|
||||
<LAMMPS_NS::utils::logmesg>`).
|
||||
|
||||
Summary of the {fmt} format syntax
|
||||
==================================
|
||||
|
||||
Reference in New Issue
Block a user