Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
fmt
Commits
05a28312
Commit
05a28312
authored
Sep 30, 2020
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update docs
parent
4d0aa4d8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
25 deletions
+23
-25
README.rst
README.rst
+2
-2
doc/index.rst
doc/index.rst
+21
-23
No files found.
README.rst
View file @
05a28312
...
@@ -17,8 +17,8 @@
...
@@ -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:
...
...
doc/index.rst
View file @
05a28312
...
@@ -48,21 +48,19 @@ The ``fmt::print`` function performs formatting and writes the result to a strea
...
@@ -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
F
ormat API also supports positional arguments useful for localization:
The
f
ormat 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
...
@@ -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:
...
@@ -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
...
@@ -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::v
5::vprint(fmt::v5::basic_string_view<char>, fmt::v5
::format_args)
call fmt::v
7::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:
...
@@ -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 compiler
s 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:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment