mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-24 12:14:26 +00:00
Update docs
This commit is contained in:
parent
40e4c227db
commit
ef7369ce90
@ -184,7 +184,7 @@ further details refer to the `source
|
|||||||
formatting (`dtoa-benchmark <https://github.com/fmtlib/dtoa-benchmark>`_)
|
formatting (`dtoa-benchmark <https://github.com/fmtlib/dtoa-benchmark>`_)
|
||||||
and as fast as `double-conversion <https://github.com/google/double-conversion>`_:
|
and as fast as `double-conversion <https://github.com/google/double-conversion>`_:
|
||||||
|
|
||||||
.. image:: https://user-images.githubusercontent.com/576385/54883977-9fe8c000-4e28-11e9-8bde-272d122e7c52.jpg
|
.. image:: https://user-images.githubusercontent.com/576385/69767160-cdaca400-112f-11ea-9fc5-347c9f83caad.png
|
||||||
:target: https://fmt.dev/unknown_mac64_clang10.0.html
|
:target: https://fmt.dev/unknown_mac64_clang10.0.html
|
||||||
|
|
||||||
Compile time and code bloat
|
Compile time and code bloat
|
||||||
|
2
doc/_templates/layout.html
vendored
2
doc/_templates/layout.html
vendored
@ -84,7 +84,7 @@
|
|||||||
<div class="jumbotron">
|
<div class="jumbotron">
|
||||||
<div class="tb-container">
|
<div class="tb-container">
|
||||||
<h1>{fmt}</h1>
|
<h1>{fmt}</h1>
|
||||||
<p class="lead">Small, safe and fast formatting library</p>
|
<p class="lead">A modern formatting library</p>
|
||||||
<div class="btn-group" role="group">
|
<div class="btn-group" role="group">
|
||||||
{% set name = 'fmt' if version.split('.')[0]|int >= 3 else 'cppformat' %}
|
{% set name = 'fmt' if version.split('.')[0]|int >= 3 else 'cppformat' %}
|
||||||
<a class="btn btn-success"
|
<a class="btn btn-success"
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
Overview
|
Overview
|
||||||
========
|
========
|
||||||
|
|
||||||
**fmt** is an open-source formatting library.
|
**{fmt}** is an open-source formatting library providing a fast and safe
|
||||||
It can be used as a fast and safe alternative to printf and IOStreams.
|
alternative to C stdio and C++ iostreams.
|
||||||
|
|
||||||
.. raw:: html
|
.. raw:: html
|
||||||
|
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">What users say:</div>
|
<div class="panel-heading">What users say:</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
Thanks for creating this library. It’s been a hole in C++ for a long
|
Thanks for creating this library. It’s been a hole in C++ for
|
||||||
time. I’ve used both boost::format and loki::SPrintf, and neither felt
|
aa long time. I’ve used both <code>boost::format</code> and
|
||||||
like the right answer. This does.
|
<code>loki::SPrintf</code>, and neither felt like the right answer.
|
||||||
|
This does.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -20,12 +21,13 @@ It can be used as a fast and safe alternative to printf and IOStreams.
|
|||||||
Format API
|
Format API
|
||||||
----------
|
----------
|
||||||
|
|
||||||
The replacement-based Format API provides a safe alternative to ``printf``,
|
The format API is similar in spirit to the C ``printf`` family of function but
|
||||||
``sprintf`` and friends with comparable or `better performance
|
is safer, simpler and serveral times `faster
|
||||||
<http://zverovich.net/2013/09/07/integer-to-string-conversion-in-cplusplus.html>`_.
|
<http://zverovich.net/2013/09/07/integer-to-string-conversion-in-cplusplus.html>`_
|
||||||
|
than common standard library implementations.
|
||||||
The `format string syntax <syntax.html>`_ is similar to the one used by
|
The `format string syntax <syntax.html>`_ is similar to the one used by
|
||||||
`str.format <http://docs.python.org/3/library/stdtypes.html#str.format>`_
|
`str.format <http://docs.python.org/3/library/stdtypes.html#str.format>`_ in
|
||||||
in Python:
|
Python:
|
||||||
|
|
||||||
.. code:: c++
|
.. code:: c++
|
||||||
|
|
||||||
@ -60,7 +62,7 @@ The Format API also supports positional arguments useful for localization:
|
|||||||
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
|
Named arguments can be created with ``fmt::arg``. This makes it easier to track
|
||||||
what goes where when multiple values are being inserted:
|
what goes where when multiple arguments are being formatted:
|
||||||
|
|
||||||
.. code:: c++
|
.. code:: c++
|
||||||
|
|
||||||
@ -72,21 +74,10 @@ an alternative, slightly terser syntax for named arguments:
|
|||||||
|
|
||||||
.. code:: c++
|
.. code:: c++
|
||||||
|
|
||||||
|
using namespace fmt::literals;
|
||||||
fmt::print("Hello, {name}! The answer is {number}. Goodbye, {name}.",
|
fmt::print("Hello, {name}! The answer is {number}. Goodbye, {name}.",
|
||||||
"name"_a="World", "number"_a=42);
|
"name"_a="World", "number"_a=42);
|
||||||
|
|
||||||
The ``_format`` suffix may be used to format string literals similar to Python:
|
|
||||||
|
|
||||||
.. code:: c++
|
|
||||||
|
|
||||||
std::string message = "{0}{1}{0}"_format("abra", "cad");
|
|
||||||
|
|
||||||
Other than the placement of the format string on the left of the operator,
|
|
||||||
``_format`` is functionally identical to ``fmt::format``. In order to use the
|
|
||||||
literal operators, they must be made visible with the directive
|
|
||||||
``using namespace fmt::literals;``. Note that this brings in only ``_a`` and
|
|
||||||
``_format`` but nothing else from the ``fmt`` namespace.
|
|
||||||
|
|
||||||
.. _safety:
|
.. _safety:
|
||||||
|
|
||||||
Safety
|
Safety
|
||||||
@ -106,11 +97,10 @@ string", because the argument ``"forty-two"`` is a string while the format code
|
|||||||
|
|
||||||
.. code:: c++
|
.. code:: c++
|
||||||
|
|
||||||
format(fmt("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 for the same reason on compilers that support
|
||||||
relaxed ``constexpr``. See `here <api.html#c.fmt>`_ for how to enable
|
relaxed ``constexpr``. See `here <api.html#c.fmt>`_ for details.
|
||||||
compile-time checks.
|
|
||||||
|
|
||||||
The following code
|
The following code
|
||||||
|
|
||||||
@ -178,13 +168,13 @@ The library is highly portable and relies only on a small set of C++11 features:
|
|||||||
* alias templates
|
* alias templates
|
||||||
|
|
||||||
These are available since GCC 4.8, Clang 3.0 and MSVC 19.0 (2015). For older
|
These are available since GCC 4.8, Clang 3.0 and MSVC 19.0 (2015). For older
|
||||||
compilers use fmt `version 4.x
|
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 continues to be
|
||||||
maintained and only requires C++98.
|
maintained and 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. In
|
||||||
particular, formatting a floating-point infinity always gives ``inf`` while the
|
particular, formatting a floating-point infinity always gives ``inf`` while the
|
||||||
output of ``printf`` is platform-dependent in this case. For example,
|
output of ``printf`` is platform-dependent. For example,
|
||||||
|
|
||||||
.. code::
|
.. code::
|
||||||
|
|
||||||
@ -197,9 +187,9 @@ always prints ``inf``.
|
|||||||
Ease of Use
|
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
|
||||||
just three header files 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 MIT `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.
|
||||||
|
|
||||||
.. raw:: html
|
.. raw:: html
|
||||||
|
Loading…
Reference in New Issue
Block a user