git repos / blockattack-game

blame: source/misc/embedded_libs/fmt-8.1.1/README.rst

normal view · raw

f8deb5b9 Poul Sander 2022-01-15 13:55 1
{fmt}
f8deb5b9 Poul Sander 2022-01-15 13:55 2
=====
f8deb5b9 Poul Sander 2022-01-15 13:55 3
f8deb5b9 Poul Sander 2022-01-15 13:55 4
.. image:: https://github.com/fmtlib/fmt/workflows/linux/badge.svg
f8deb5b9 Poul Sander 2022-01-15 13:55 5
   :target: https://github.com/fmtlib/fmt/actions?query=workflow%3Alinux
f8deb5b9 Poul Sander 2022-01-15 13:55 6
f8deb5b9 Poul Sander 2022-01-15 13:55 7
.. image:: https://github.com/fmtlib/fmt/workflows/macos/badge.svg
f8deb5b9 Poul Sander 2022-01-15 13:55 8
   :target: https://github.com/fmtlib/fmt/actions?query=workflow%3Amacos
f8deb5b9 Poul Sander 2022-01-15 13:55 9
f8deb5b9 Poul Sander 2022-01-15 13:55 10
.. image:: https://github.com/fmtlib/fmt/workflows/windows/badge.svg
f8deb5b9 Poul Sander 2022-01-15 13:55 11
   :target: https://github.com/fmtlib/fmt/actions?query=workflow%3Awindows
f8deb5b9 Poul Sander 2022-01-15 13:55 12
f8deb5b9 Poul Sander 2022-01-15 13:55 13
.. image:: https://ci.appveyor.com/api/projects/status/ehjkiefde6gucy1v?svg=true
f8deb5b9 Poul Sander 2022-01-15 13:55 14
   :target: https://ci.appveyor.com/project/vitaut/fmt
f8deb5b9 Poul Sander 2022-01-15 13:55 15
f8deb5b9 Poul Sander 2022-01-15 13:55 16
.. image:: https://oss-fuzz-build-logs.storage.googleapis.com/badges/fmt.svg
f8deb5b9 Poul Sander 2022-01-15 13:55 17
   :alt: fmt is continuously fuzzed at oss-fuzz
f8deb5b9 Poul Sander 2022-01-15 13:55 18
   :target: https://bugs.chromium.org/p/oss-fuzz/issues/list?\
f8deb5b9 Poul Sander 2022-01-15 13:55 19
            colspec=ID%20Type%20Component%20Status%20Proj%20Reported%20Owner%20\
f8deb5b9 Poul Sander 2022-01-15 13:55 20
            Summary&q=proj%3Dfmt&can=1
f8deb5b9 Poul Sander 2022-01-15 13:55 21
f8deb5b9 Poul Sander 2022-01-15 13:55 22
.. image:: https://img.shields.io/badge/stackoverflow-fmt-blue.svg
f8deb5b9 Poul Sander 2022-01-15 13:55 23
   :alt: Ask questions at StackOverflow with the tag fmt
f8deb5b9 Poul Sander 2022-01-15 13:55 24
   :target: https://stackoverflow.com/questions/tagged/fmt
f8deb5b9 Poul Sander 2022-01-15 13:55 25
f8deb5b9 Poul Sander 2022-01-15 13:55 26
**{fmt}** is an open-source formatting library providing a fast and safe
f8deb5b9 Poul Sander 2022-01-15 13:55 27
alternative to C stdio and C++ iostreams.
f8deb5b9 Poul Sander 2022-01-15 13:55 28
f8deb5b9 Poul Sander 2022-01-15 13:55 29
If you like this project, please consider donating to the BYSOL
f8deb5b9 Poul Sander 2022-01-15 13:55 30
Foundation that helps victims of political repressions in Belarus:
f8deb5b9 Poul Sander 2022-01-15 13:55 31
https://bysol.org/en/bs/general/.
f8deb5b9 Poul Sander 2022-01-15 13:55 32
f8deb5b9 Poul Sander 2022-01-15 13:55 33
`Documentation <https://fmt.dev>`__
f8deb5b9 Poul Sander 2022-01-15 13:55 34
f8deb5b9 Poul Sander 2022-01-15 13:55 35
Q&A: ask questions on `StackOverflow with the tag fmt
f8deb5b9 Poul Sander 2022-01-15 13:55 36
<https://stackoverflow.com/questions/tagged/fmt>`_.
f8deb5b9 Poul Sander 2022-01-15 13:55 37
f8deb5b9 Poul Sander 2022-01-15 13:55 38
Try {fmt} in `Compiler Explorer <https://godbolt.org/z/Eq5763>`_.
f8deb5b9 Poul Sander 2022-01-15 13:55 39
f8deb5b9 Poul Sander 2022-01-15 13:55 40
Features
f8deb5b9 Poul Sander 2022-01-15 13:55 41
--------
f8deb5b9 Poul Sander 2022-01-15 13:55 42
f8deb5b9 Poul Sander 2022-01-15 13:55 43
* Simple `format API <https://fmt.dev/latest/api.html>`_ with positional arguments
f8deb5b9 Poul Sander 2022-01-15 13:55 44
  for localization
f8deb5b9 Poul Sander 2022-01-15 13:55 45
* Implementation of `C++20 std::format
f8deb5b9 Poul Sander 2022-01-15 13:55 46
  <https://en.cppreference.com/w/cpp/utility/format>`__
f8deb5b9 Poul Sander 2022-01-15 13:55 47
* `Format string syntax <https://fmt.dev/latest/syntax.html>`_ similar to Python's
f8deb5b9 Poul Sander 2022-01-15 13:55 48
  `format <https://docs.python.org/3/library/stdtypes.html#str.format>`_
f8deb5b9 Poul Sander 2022-01-15 13:55 49
* Fast IEEE 754 floating-point formatter with correct rounding, shortness and
f8deb5b9 Poul Sander 2022-01-15 13:55 50
  round-trip guarantees
f8deb5b9 Poul Sander 2022-01-15 13:55 51
* Safe `printf implementation
f8deb5b9 Poul Sander 2022-01-15 13:55 52
  <https://fmt.dev/latest/api.html#printf-formatting>`_ including the POSIX
f8deb5b9 Poul Sander 2022-01-15 13:55 53
  extension for positional arguments
f8deb5b9 Poul Sander 2022-01-15 13:55 54
* Extensibility: `support for user-defined types
f8deb5b9 Poul Sander 2022-01-15 13:55 55
  <https://fmt.dev/latest/api.html#formatting-user-defined-types>`_
f8deb5b9 Poul Sander 2022-01-15 13:55 56
* High performance: faster than common standard library implementations of
f8deb5b9 Poul Sander 2022-01-15 13:55 57
  ``(s)printf``, iostreams, ``to_string`` and ``to_chars``, see `Speed tests`_
f8deb5b9 Poul Sander 2022-01-15 13:55 58
  and `Converting a hundred million integers to strings per second
f8deb5b9 Poul Sander 2022-01-15 13:55 59
  <http://www.zverovich.net/2020/06/13/fast-int-to-string-revisited.html>`_
f8deb5b9 Poul Sander 2022-01-15 13:55 60
* Small code size both in terms of source code with the minimum configuration
f8deb5b9 Poul Sander 2022-01-15 13:55 61
  consisting of just three files, ``core.h``, ``format.h`` and ``format-inl.h``,
f8deb5b9 Poul Sander 2022-01-15 13:55 62
  and compiled code; see `Compile time and code bloat`_
f8deb5b9 Poul Sander 2022-01-15 13:55 63
* Reliability: the library has an extensive set of `tests
f8deb5b9 Poul Sander 2022-01-15 13:55 64
  <https://github.com/fmtlib/fmt/tree/master/test>`_ and is `continuously fuzzed
f8deb5b9 Poul Sander 2022-01-15 13:55 65
  <https://bugs.chromium.org/p/oss-fuzz/issues/list?colspec=ID%20Type%20
f8deb5b9 Poul Sander 2022-01-15 13:55 66
  Component%20Status%20Proj%20Reported%20Owner%20Summary&q=proj%3Dfmt&can=1>`_
f8deb5b9 Poul Sander 2022-01-15 13:55 67
* Safety: the library is fully type safe, errors in format strings can be
f8deb5b9 Poul Sander 2022-01-15 13:55 68
  reported at compile time, automatic memory management prevents buffer overflow
f8deb5b9 Poul Sander 2022-01-15 13:55 69
  errors
f8deb5b9 Poul Sander 2022-01-15 13:55 70
* Ease of use: small self-contained code base, no external dependencies,
f8deb5b9 Poul Sander 2022-01-15 13:55 71
  permissive MIT `license
f8deb5b9 Poul Sander 2022-01-15 13:55 72
  <https://github.com/fmtlib/fmt/blob/master/LICENSE.rst>`_
f8deb5b9 Poul Sander 2022-01-15 13:55 73
* `Portability <https://fmt.dev/latest/index.html#portability>`_ with
f8deb5b9 Poul Sander 2022-01-15 13:55 74
  consistent output across platforms and support for older compilers
f8deb5b9 Poul Sander 2022-01-15 13:55 75
* Clean warning-free codebase even on high warning levels such as
f8deb5b9 Poul Sander 2022-01-15 13:55 76
  ``-Wall -Wextra -pedantic``
f8deb5b9 Poul Sander 2022-01-15 13:55 77
* Locale-independence by default
f8deb5b9 Poul Sander 2022-01-15 13:55 78
* Optional header-only configuration enabled with the ``FMT_HEADER_ONLY`` macro
f8deb5b9 Poul Sander 2022-01-15 13:55 79
f8deb5b9 Poul Sander 2022-01-15 13:55 80
See the `documentation <https://fmt.dev>`_ for more details.
f8deb5b9 Poul Sander 2022-01-15 13:55 81
f8deb5b9 Poul Sander 2022-01-15 13:55 82
Examples
f8deb5b9 Poul Sander 2022-01-15 13:55 83
--------
f8deb5b9 Poul Sander 2022-01-15 13:55 84
f8deb5b9 Poul Sander 2022-01-15 13:55 85
**Print to stdout** (`run <https://godbolt.org/z/Tevcjh>`_)
f8deb5b9 Poul Sander 2022-01-15 13:55 86
f8deb5b9 Poul Sander 2022-01-15 13:55 87
.. code:: c++
f8deb5b9 Poul Sander 2022-01-15 13:55 88
f8deb5b9 Poul Sander 2022-01-15 13:55 89
    #include <fmt/core.h>
f8deb5b9 Poul Sander 2022-01-15 13:55 90
    
f8deb5b9 Poul Sander 2022-01-15 13:55 91
    int main() {
f8deb5b9 Poul Sander 2022-01-15 13:55 92
      fmt::print("Hello, world!\n");
f8deb5b9 Poul Sander 2022-01-15 13:55 93
    }
f8deb5b9 Poul Sander 2022-01-15 13:55 94
f8deb5b9 Poul Sander 2022-01-15 13:55 95
**Format a string** (`run <https://godbolt.org/z/oK8h33>`_)
f8deb5b9 Poul Sander 2022-01-15 13:55 96
f8deb5b9 Poul Sander 2022-01-15 13:55 97
.. code:: c++
f8deb5b9 Poul Sander 2022-01-15 13:55 98
f8deb5b9 Poul Sander 2022-01-15 13:55 99
    std::string s = fmt::format("The answer is {}.", 42);
f8deb5b9 Poul Sander 2022-01-15 13:55 100
    // s == "The answer is 42."
f8deb5b9 Poul Sander 2022-01-15 13:55 101
f8deb5b9 Poul Sander 2022-01-15 13:55 102
**Format a string using positional arguments** (`run <https://godbolt.org/z/Yn7Txe>`_)
f8deb5b9 Poul Sander 2022-01-15 13:55 103
f8deb5b9 Poul Sander 2022-01-15 13:55 104
.. code:: c++
f8deb5b9 Poul Sander 2022-01-15 13:55 105
f8deb5b9 Poul Sander 2022-01-15 13:55 106
    std::string s = fmt::format("I'd rather be {1} than {0}.", "right", "happy");
f8deb5b9 Poul Sander 2022-01-15 13:55 107
    // s == "I'd rather be happy than right."
f8deb5b9 Poul Sander 2022-01-15 13:55 108
f8deb5b9 Poul Sander 2022-01-15 13:55 109
**Print chrono durations** (`run <https://godbolt.org/z/K8s4Mc>`_)
f8deb5b9 Poul Sander 2022-01-15 13:55 110
f8deb5b9 Poul Sander 2022-01-15 13:55 111
.. code:: c++
f8deb5b9 Poul Sander 2022-01-15 13:55 112
f8deb5b9 Poul Sander 2022-01-15 13:55 113
    #include <fmt/chrono.h>
f8deb5b9 Poul Sander 2022-01-15 13:55 114
f8deb5b9 Poul Sander 2022-01-15 13:55 115
    int main() {
f8deb5b9 Poul Sander 2022-01-15 13:55 116
      using namespace std::literals::chrono_literals;
f8deb5b9 Poul Sander 2022-01-15 13:55 117
      fmt::print("Default format: {} {}\n", 42s, 100ms);
f8deb5b9 Poul Sander 2022-01-15 13:55 118
      fmt::print("strftime-like format: {:%H:%M:%S}\n", 3h + 15min + 30s);
f8deb5b9 Poul Sander 2022-01-15 13:55 119
    }
f8deb5b9 Poul Sander 2022-01-15 13:55 120
f8deb5b9 Poul Sander 2022-01-15 13:55 121
Output::
f8deb5b9 Poul Sander 2022-01-15 13:55 122
f8deb5b9 Poul Sander 2022-01-15 13:55 123
    Default format: 42s 100ms
f8deb5b9 Poul Sander 2022-01-15 13:55 124
    strftime-like format: 03:15:30
f8deb5b9 Poul Sander 2022-01-15 13:55 125
f8deb5b9 Poul Sander 2022-01-15 13:55 126
**Print a container** (`run <https://godbolt.org/z/MjsY7c>`_)
f8deb5b9 Poul Sander 2022-01-15 13:55 127
f8deb5b9 Poul Sander 2022-01-15 13:55 128
.. code:: c++
f8deb5b9 Poul Sander 2022-01-15 13:55 129
f8deb5b9 Poul Sander 2022-01-15 13:55 130
    #include <vector>
f8deb5b9 Poul Sander 2022-01-15 13:55 131
    #include <fmt/ranges.h>
f8deb5b9 Poul Sander 2022-01-15 13:55 132
f8deb5b9 Poul Sander 2022-01-15 13:55 133
    int main() {
f8deb5b9 Poul Sander 2022-01-15 13:55 134
      std::vector<int> v = {1, 2, 3};
f8deb5b9 Poul Sander 2022-01-15 13:55 135
      fmt::print("{}\n", v);
f8deb5b9 Poul Sander 2022-01-15 13:55 136
    }
f8deb5b9 Poul Sander 2022-01-15 13:55 137
f8deb5b9 Poul Sander 2022-01-15 13:55 138
Output::
f8deb5b9 Poul Sander 2022-01-15 13:55 139
f8deb5b9 Poul Sander 2022-01-15 13:55 140
    [1, 2, 3]
f8deb5b9 Poul Sander 2022-01-15 13:55 141
f8deb5b9 Poul Sander 2022-01-15 13:55 142
**Check a format string at compile time**
f8deb5b9 Poul Sander 2022-01-15 13:55 143
f8deb5b9 Poul Sander 2022-01-15 13:55 144
.. code:: c++
f8deb5b9 Poul Sander 2022-01-15 13:55 145
f8deb5b9 Poul Sander 2022-01-15 13:55 146
    std::string s = fmt::format("{:d}", "I am not a number");
f8deb5b9 Poul Sander 2022-01-15 13:55 147
f8deb5b9 Poul Sander 2022-01-15 13:55 148
This gives a compile-time error in C++20 because ``d`` is an invalid format
f8deb5b9 Poul Sander 2022-01-15 13:55 149
specifier for a string.
f8deb5b9 Poul Sander 2022-01-15 13:55 150
f8deb5b9 Poul Sander 2022-01-15 13:55 151
**Write a file from a single thread**
f8deb5b9 Poul Sander 2022-01-15 13:55 152
f8deb5b9 Poul Sander 2022-01-15 13:55 153
.. code:: c++
f8deb5b9 Poul Sander 2022-01-15 13:55 154
f8deb5b9 Poul Sander 2022-01-15 13:55 155
    #include <fmt/os.h>
f8deb5b9 Poul Sander 2022-01-15 13:55 156
f8deb5b9 Poul Sander 2022-01-15 13:55 157
    int main() {
f8deb5b9 Poul Sander 2022-01-15 13:55 158
      auto out = fmt::output_file("guide.txt");
f8deb5b9 Poul Sander 2022-01-15 13:55 159
      out.print("Don't {}", "Panic");
f8deb5b9 Poul Sander 2022-01-15 13:55 160
    }
f8deb5b9 Poul Sander 2022-01-15 13:55 161
f8deb5b9 Poul Sander 2022-01-15 13:55 162
This can be `5 to 9 times faster than fprintf
f8deb5b9 Poul Sander 2022-01-15 13:55 163
<http://www.zverovich.net/2020/08/04/optimal-file-buffer-size.html>`_.
f8deb5b9 Poul Sander 2022-01-15 13:55 164
f8deb5b9 Poul Sander 2022-01-15 13:55 165
**Print with colors and text styles**
f8deb5b9 Poul Sander 2022-01-15 13:55 166
f8deb5b9 Poul Sander 2022-01-15 13:55 167
.. code:: c++
f8deb5b9 Poul Sander 2022-01-15 13:55 168
f8deb5b9 Poul Sander 2022-01-15 13:55 169
    #include <fmt/color.h>
f8deb5b9 Poul Sander 2022-01-15 13:55 170
f8deb5b9 Poul Sander 2022-01-15 13:55 171
    int main() {
f8deb5b9 Poul Sander 2022-01-15 13:55 172
      fmt::print(fg(fmt::color::crimson) | fmt::emphasis::bold,
f8deb5b9 Poul Sander 2022-01-15 13:55 173
                 "Hello, {}!\n", "world");
f8deb5b9 Poul Sander 2022-01-15 13:55 174
      fmt::print(fg(fmt::color::floral_white) | bg(fmt::color::slate_gray) |
f8deb5b9 Poul Sander 2022-01-15 13:55 175
                 fmt::emphasis::underline, "Hello, {}!\n", "мир");
f8deb5b9 Poul Sander 2022-01-15 13:55 176
      fmt::print(fg(fmt::color::steel_blue) | fmt::emphasis::italic,
f8deb5b9 Poul Sander 2022-01-15 13:55 177
                 "Hello, {}!\n", "世界");
f8deb5b9 Poul Sander 2022-01-15 13:55 178
    }
f8deb5b9 Poul Sander 2022-01-15 13:55 179
f8deb5b9 Poul Sander 2022-01-15 13:55 180
Output on a modern terminal:
f8deb5b9 Poul Sander 2022-01-15 13:55 181
f8deb5b9 Poul Sander 2022-01-15 13:55 182
.. image:: https://user-images.githubusercontent.com/
f8deb5b9 Poul Sander 2022-01-15 13:55 183
           576385/88485597-d312f600-cf2b-11ea-9cbe-61f535a86e28.png
f8deb5b9 Poul Sander 2022-01-15 13:55 184
f8deb5b9 Poul Sander 2022-01-15 13:55 185
Benchmarks
f8deb5b9 Poul Sander 2022-01-15 13:55 186
----------
f8deb5b9 Poul Sander 2022-01-15 13:55 187
f8deb5b9 Poul Sander 2022-01-15 13:55 188
Speed tests
f8deb5b9 Poul Sander 2022-01-15 13:55 189
~~~~~~~~~~~
f8deb5b9 Poul Sander 2022-01-15 13:55 190
f8deb5b9 Poul Sander 2022-01-15 13:55 191
================= ============= ===========
f8deb5b9 Poul Sander 2022-01-15 13:55 192
Library           Method        Run Time, s
f8deb5b9 Poul Sander 2022-01-15 13:55 193
================= ============= ===========
f8deb5b9 Poul Sander 2022-01-15 13:55 194
libc              printf          1.04
f8deb5b9 Poul Sander 2022-01-15 13:55 195
libc++            std::ostream    3.05
f8deb5b9 Poul Sander 2022-01-15 13:55 196
{fmt} 6.1.1       fmt::print      0.75
f8deb5b9 Poul Sander 2022-01-15 13:55 197
Boost Format 1.67 boost::format   7.24
f8deb5b9 Poul Sander 2022-01-15 13:55 198
Folly Format      folly::format   2.23
f8deb5b9 Poul Sander 2022-01-15 13:55 199
================= ============= ===========
f8deb5b9 Poul Sander 2022-01-15 13:55 200
f8deb5b9 Poul Sander 2022-01-15 13:55 201
{fmt} is the fastest of the benchmarked methods, ~35% faster than ``printf``.
f8deb5b9 Poul Sander 2022-01-15 13:55 202
f8deb5b9 Poul Sander 2022-01-15 13:55 203
The above results were generated by building ``tinyformat_test.cpp`` on macOS
f8deb5b9 Poul Sander 2022-01-15 13:55 204
10.14.6 with ``clang++ -O3 -DNDEBUG -DSPEED_TEST -DHAVE_FORMAT``, and taking the
f8deb5b9 Poul Sander 2022-01-15 13:55 205
best of three runs. In the test, the format string ``"%0.10f:%04d:%+g:%s:%p:%c:%%\n"``
f8deb5b9 Poul Sander 2022-01-15 13:55 206
or equivalent is filled 2,000,000 times with output sent to ``/dev/null``; for
f8deb5b9 Poul Sander 2022-01-15 13:55 207
further details refer to the `source
f8deb5b9 Poul Sander 2022-01-15 13:55 208
<https://github.com/fmtlib/format-benchmark/blob/master/src/tinyformat-test.cc>`_.
f8deb5b9 Poul Sander 2022-01-15 13:55 209
f8deb5b9 Poul Sander 2022-01-15 13:55 210
{fmt} is up to 20-30x faster than ``std::ostringstream`` and ``sprintf`` on
f8deb5b9 Poul Sander 2022-01-15 13:55 211
floating-point formatting (`dtoa-benchmark <https://github.com/fmtlib/dtoa-benchmark>`_)
f8deb5b9 Poul Sander 2022-01-15 13:55 212
and faster than `double-conversion <https://github.com/google/double-conversion>`_ and
f8deb5b9 Poul Sander 2022-01-15 13:55 213
`ryu <https://github.com/ulfjack/ryu>`_:
f8deb5b9 Poul Sander 2022-01-15 13:55 214
f8deb5b9 Poul Sander 2022-01-15 13:55 215
.. image:: https://user-images.githubusercontent.com/576385/
f8deb5b9 Poul Sander 2022-01-15 13:55 216
           95684665-11719600-0ba8-11eb-8e5b-972ff4e49428.png
f8deb5b9 Poul Sander 2022-01-15 13:55 217
   :target: https://fmt.dev/unknown_mac64_clang12.0.html
f8deb5b9 Poul Sander 2022-01-15 13:55 218
f8deb5b9 Poul Sander 2022-01-15 13:55 219
Compile time and code bloat
f8deb5b9 Poul Sander 2022-01-15 13:55 220
~~~~~~~~~~~~~~~~~~~~~~~~~~~
f8deb5b9 Poul Sander 2022-01-15 13:55 221
f8deb5b9 Poul Sander 2022-01-15 13:55 222
The script `bloat-test.py
f8deb5b9 Poul Sander 2022-01-15 13:55 223
<https://github.com/fmtlib/format-benchmark/blob/master/bloat-test.py>`_
f8deb5b9 Poul Sander 2022-01-15 13:55 224
from `format-benchmark <https://github.com/fmtlib/format-benchmark>`_
f8deb5b9 Poul Sander 2022-01-15 13:55 225
tests compile time and code bloat for nontrivial projects.
f8deb5b9 Poul Sander 2022-01-15 13:55 226
It generates 100 translation units and uses ``printf()`` or its alternative
f8deb5b9 Poul Sander 2022-01-15 13:55 227
five times in each to simulate a medium sized project.  The resulting
f8deb5b9 Poul Sander 2022-01-15 13:55 228
executable size and compile time (Apple LLVM version 8.1.0 (clang-802.0.42),
f8deb5b9 Poul Sander 2022-01-15 13:55 229
macOS Sierra, best of three) is shown in the following tables.
f8deb5b9 Poul Sander 2022-01-15 13:55 230
f8deb5b9 Poul Sander 2022-01-15 13:55 231
**Optimized build (-O3)**
f8deb5b9 Poul Sander 2022-01-15 13:55 232
f8deb5b9 Poul Sander 2022-01-15 13:55 233
============= =============== ==================== ==================
f8deb5b9 Poul Sander 2022-01-15 13:55 234
Method        Compile Time, s Executable size, KiB Stripped size, KiB
f8deb5b9 Poul Sander 2022-01-15 13:55 235
============= =============== ==================== ==================
f8deb5b9 Poul Sander 2022-01-15 13:55 236
printf                    2.6                   29                 26
f8deb5b9 Poul Sander 2022-01-15 13:55 237
printf+string            16.4                   29                 26
f8deb5b9 Poul Sander 2022-01-15 13:55 238
iostreams                31.1                   59                 55
f8deb5b9 Poul Sander 2022-01-15 13:55 239
{fmt}                    19.0                   37                 34
f8deb5b9 Poul Sander 2022-01-15 13:55 240
Boost Format             91.9                  226                203
f8deb5b9 Poul Sander 2022-01-15 13:55 241
Folly Format            115.7                  101                 88
f8deb5b9 Poul Sander 2022-01-15 13:55 242
============= =============== ==================== ==================
f8deb5b9 Poul Sander 2022-01-15 13:55 243
f8deb5b9 Poul Sander 2022-01-15 13:55 244
As you can see, {fmt} has 60% less overhead in terms of resulting binary code
f8deb5b9 Poul Sander 2022-01-15 13:55 245
size compared to iostreams and comes pretty close to ``printf``. Boost Format
f8deb5b9 Poul Sander 2022-01-15 13:55 246
and Folly Format have the largest overheads.
f8deb5b9 Poul Sander 2022-01-15 13:55 247
f8deb5b9 Poul Sander 2022-01-15 13:55 248
``printf+string`` is the same as ``printf`` but with extra ``<string>``
f8deb5b9 Poul Sander 2022-01-15 13:55 249
include to measure the overhead of the latter.
f8deb5b9 Poul Sander 2022-01-15 13:55 250
f8deb5b9 Poul Sander 2022-01-15 13:55 251
**Non-optimized build**
f8deb5b9 Poul Sander 2022-01-15 13:55 252
f8deb5b9 Poul Sander 2022-01-15 13:55 253
============= =============== ==================== ==================
f8deb5b9 Poul Sander 2022-01-15 13:55 254
Method        Compile Time, s Executable size, KiB Stripped size, KiB
f8deb5b9 Poul Sander 2022-01-15 13:55 255
============= =============== ==================== ==================
f8deb5b9 Poul Sander 2022-01-15 13:55 256
printf                    2.2                   33                 30
f8deb5b9 Poul Sander 2022-01-15 13:55 257
printf+string            16.0                   33                 30
f8deb5b9 Poul Sander 2022-01-15 13:55 258
iostreams                28.3                   56                 52
f8deb5b9 Poul Sander 2022-01-15 13:55 259
{fmt}                    18.2                   59                 50
f8deb5b9 Poul Sander 2022-01-15 13:55 260
Boost Format             54.1                  365                303
f8deb5b9 Poul Sander 2022-01-15 13:55 261
Folly Format             79.9                  445                430
f8deb5b9 Poul Sander 2022-01-15 13:55 262
============= =============== ==================== ==================
f8deb5b9 Poul Sander 2022-01-15 13:55 263
f8deb5b9 Poul Sander 2022-01-15 13:55 264
``libc``, ``lib(std)c++`` and ``libfmt`` are all linked as shared libraries to
f8deb5b9 Poul Sander 2022-01-15 13:55 265
compare formatting function overhead only. Boost Format is a
f8deb5b9 Poul Sander 2022-01-15 13:55 266
header-only library so it doesn't provide any linkage options.
f8deb5b9 Poul Sander 2022-01-15 13:55 267
f8deb5b9 Poul Sander 2022-01-15 13:55 268
Running the tests
f8deb5b9 Poul Sander 2022-01-15 13:55 269
~~~~~~~~~~~~~~~~~
f8deb5b9 Poul Sander 2022-01-15 13:55 270
f8deb5b9 Poul Sander 2022-01-15 13:55 271
Please refer to `Building the library`__ for the instructions on how to build
f8deb5b9 Poul Sander 2022-01-15 13:55 272
the library and run the unit tests.
f8deb5b9 Poul Sander 2022-01-15 13:55 273
f8deb5b9 Poul Sander 2022-01-15 13:55 274
__ https://fmt.dev/latest/usage.html#building-the-library
f8deb5b9 Poul Sander 2022-01-15 13:55 275
f8deb5b9 Poul Sander 2022-01-15 13:55 276
Benchmarks reside in a separate repository,
f8deb5b9 Poul Sander 2022-01-15 13:55 277
`format-benchmarks <https://github.com/fmtlib/format-benchmark>`_,
f8deb5b9 Poul Sander 2022-01-15 13:55 278
so to run the benchmarks you first need to clone this repository and
f8deb5b9 Poul Sander 2022-01-15 13:55 279
generate Makefiles with CMake::
f8deb5b9 Poul Sander 2022-01-15 13:55 280
f8deb5b9 Poul Sander 2022-01-15 13:55 281
    $ git clone --recursive https://github.com/fmtlib/format-benchmark.git
f8deb5b9 Poul Sander 2022-01-15 13:55 282
    $ cd format-benchmark
f8deb5b9 Poul Sander 2022-01-15 13:55 283
    $ cmake .
f8deb5b9 Poul Sander 2022-01-15 13:55 284
f8deb5b9 Poul Sander 2022-01-15 13:55 285
Then you can run the speed test::
f8deb5b9 Poul Sander 2022-01-15 13:55 286
f8deb5b9 Poul Sander 2022-01-15 13:55 287
    $ make speed-test
f8deb5b9 Poul Sander 2022-01-15 13:55 288
f8deb5b9 Poul Sander 2022-01-15 13:55 289
or the bloat test::
f8deb5b9 Poul Sander 2022-01-15 13:55 290
f8deb5b9 Poul Sander 2022-01-15 13:55 291
    $ make bloat-test
f8deb5b9 Poul Sander 2022-01-15 13:55 292
    
f8deb5b9 Poul Sander 2022-01-15 13:55 293
Migrating code
f8deb5b9 Poul Sander 2022-01-15 13:55 294
--------------
f8deb5b9 Poul Sander 2022-01-15 13:55 295
f8deb5b9 Poul Sander 2022-01-15 13:55 296
`clang-tidy-fmt <https://github.com/mikecrowe/clang-tidy-fmt>`_ provides clang
f8deb5b9 Poul Sander 2022-01-15 13:55 297
tidy checks for converting occurrences of ``printf`` and ``fprintf`` to
f8deb5b9 Poul Sander 2022-01-15 13:55 298
``fmt::print``.
f8deb5b9 Poul Sander 2022-01-15 13:55 299
f8deb5b9 Poul Sander 2022-01-15 13:55 300
Projects using this library
f8deb5b9 Poul Sander 2022-01-15 13:55 301
---------------------------
f8deb5b9 Poul Sander 2022-01-15 13:55 302
f8deb5b9 Poul Sander 2022-01-15 13:55 303
* `0 A.D. <https://play0ad.com/>`_: a free, open-source, cross-platform
f8deb5b9 Poul Sander 2022-01-15 13:55 304
  real-time strategy game
f8deb5b9 Poul Sander 2022-01-15 13:55 305
f8deb5b9 Poul Sander 2022-01-15 13:55 306
* `2GIS <https://2gis.ru/>`_: free business listings with a city map
f8deb5b9 Poul Sander 2022-01-15 13:55 307
f8deb5b9 Poul Sander 2022-01-15 13:55 308
* `AMPL/MP <https://github.com/ampl/mp>`_:
f8deb5b9 Poul Sander 2022-01-15 13:55 309
  an open-source library for mathematical programming
f8deb5b9 Poul Sander 2022-01-15 13:55 310
f8deb5b9 Poul Sander 2022-01-15 13:55 311
* `Aseprite <https://github.com/aseprite/aseprite>`_:
f8deb5b9 Poul Sander 2022-01-15 13:55 312
  animated sprite editor & pixel art tool 
f8deb5b9 Poul Sander 2022-01-15 13:55 313
f8deb5b9 Poul Sander 2022-01-15 13:55 314
* `AvioBook <https://www.aviobook.aero/en>`_: a comprehensive aircraft
f8deb5b9 Poul Sander 2022-01-15 13:55 315
  operations suite
f8deb5b9 Poul Sander 2022-01-15 13:55 316
  
f8deb5b9 Poul Sander 2022-01-15 13:55 317
* `Blizzard Battle.net <https://battle.net/>`_: an online gaming platform
f8deb5b9 Poul Sander 2022-01-15 13:55 318
  
f8deb5b9 Poul Sander 2022-01-15 13:55 319
* `Celestia <https://celestia.space/>`_: real-time 3D visualization of space
f8deb5b9 Poul Sander 2022-01-15 13:55 320
f8deb5b9 Poul Sander 2022-01-15 13:55 321
* `Ceph <https://ceph.com/>`_: a scalable distributed storage system
f8deb5b9 Poul Sander 2022-01-15 13:55 322
f8deb5b9 Poul Sander 2022-01-15 13:55 323
* `ccache <https://ccache.dev/>`_: a compiler cache
f8deb5b9 Poul Sander 2022-01-15 13:55 324
f8deb5b9 Poul Sander 2022-01-15 13:55 325
* `ClickHouse <https://github.com/ClickHouse/ClickHouse>`_: analytical database
f8deb5b9 Poul Sander 2022-01-15 13:55 326
  management system
f8deb5b9 Poul Sander 2022-01-15 13:55 327
f8deb5b9 Poul Sander 2022-01-15 13:55 328
* `CUAUV <https://cuauv.org/>`_: Cornell University's autonomous underwater
f8deb5b9 Poul Sander 2022-01-15 13:55 329
  vehicle
f8deb5b9 Poul Sander 2022-01-15 13:55 330
f8deb5b9 Poul Sander 2022-01-15 13:55 331
* `Drake <https://drake.mit.edu/>`_: a planning, control, and analysis toolbox
f8deb5b9 Poul Sander 2022-01-15 13:55 332
  for nonlinear dynamical systems (MIT)
f8deb5b9 Poul Sander 2022-01-15 13:55 333
f8deb5b9 Poul Sander 2022-01-15 13:55 334
* `Envoy <https://lyft.github.io/envoy/>`_: C++ L7 proxy and communication bus
f8deb5b9 Poul Sander 2022-01-15 13:55 335
  (Lyft)
f8deb5b9 Poul Sander 2022-01-15 13:55 336
f8deb5b9 Poul Sander 2022-01-15 13:55 337
* `FiveM <https://fivem.net/>`_: a modification framework for GTA V
f8deb5b9 Poul Sander 2022-01-15 13:55 338
f8deb5b9 Poul Sander 2022-01-15 13:55 339
* `fmtlog <https://github.com/MengRao/fmtlog>`_: a performant fmtlib-style
f8deb5b9 Poul Sander 2022-01-15 13:55 340
  logging library with latency in nanoseconds
f8deb5b9 Poul Sander 2022-01-15 13:55 341
f8deb5b9 Poul Sander 2022-01-15 13:55 342
* `Folly <https://github.com/facebook/folly>`_: Facebook open-source library
f8deb5b9 Poul Sander 2022-01-15 13:55 343
f8deb5b9 Poul Sander 2022-01-15 13:55 344
* `Grand Mountain Adventure
f8deb5b9 Poul Sander 2022-01-15 13:55 345
  <https://store.steampowered.com/app/1247360/Grand_Mountain_Adventure/>`_:
f8deb5b9 Poul Sander 2022-01-15 13:55 346
  A beautiful open-world ski & snowboarding game
f8deb5b9 Poul Sander 2022-01-15 13:55 347
f8deb5b9 Poul Sander 2022-01-15 13:55 348
* `HarpyWar/pvpgn <https://github.com/pvpgn/pvpgn-server>`_:
f8deb5b9 Poul Sander 2022-01-15 13:55 349
  Player vs Player Gaming Network with tweaks
f8deb5b9 Poul Sander 2022-01-15 13:55 350
f8deb5b9 Poul Sander 2022-01-15 13:55 351
* `KBEngine <https://github.com/kbengine/kbengine>`_: an open-source MMOG server
f8deb5b9 Poul Sander 2022-01-15 13:55 352
  engine
f8deb5b9 Poul Sander 2022-01-15 13:55 353
f8deb5b9 Poul Sander 2022-01-15 13:55 354
* `Keypirinha <https://keypirinha.com/>`_: a semantic launcher for Windows
f8deb5b9 Poul Sander 2022-01-15 13:55 355
f8deb5b9 Poul Sander 2022-01-15 13:55 356
* `Kodi <https://kodi.tv/>`_ (formerly xbmc): home theater software
f8deb5b9 Poul Sander 2022-01-15 13:55 357
f8deb5b9 Poul Sander 2022-01-15 13:55 358
* `Knuth <https://kth.cash/>`_: high-performance Bitcoin full-node
f8deb5b9 Poul Sander 2022-01-15 13:55 359
f8deb5b9 Poul Sander 2022-01-15 13:55 360
* `Microsoft Verona <https://github.com/microsoft/verona>`_:
f8deb5b9 Poul Sander 2022-01-15 13:55 361
  research programming language for concurrent ownership
f8deb5b9 Poul Sander 2022-01-15 13:55 362
f8deb5b9 Poul Sander 2022-01-15 13:55 363
* `MongoDB <https://mongodb.com/>`_: distributed document database
f8deb5b9 Poul Sander 2022-01-15 13:55 364
f8deb5b9 Poul Sander 2022-01-15 13:55 365
* `MongoDB Smasher <https://github.com/duckie/mongo_smasher>`_: a small tool to
f8deb5b9 Poul Sander 2022-01-15 13:55 366
  generate randomized datasets
f8deb5b9 Poul Sander 2022-01-15 13:55 367
f8deb5b9 Poul Sander 2022-01-15 13:55 368
* `OpenSpace <https://openspaceproject.com/>`_: an open-source
f8deb5b9 Poul Sander 2022-01-15 13:55 369
  astrovisualization framework
f8deb5b9 Poul Sander 2022-01-15 13:55 370
f8deb5b9 Poul Sander 2022-01-15 13:55 371
* `PenUltima Online (POL) <https://www.polserver.com/>`_:
f8deb5b9 Poul Sander 2022-01-15 13:55 372
  an MMO server, compatible with most Ultima Online clients
f8deb5b9 Poul Sander 2022-01-15 13:55 373
f8deb5b9 Poul Sander 2022-01-15 13:55 374
* `PyTorch <https://github.com/pytorch/pytorch>`_: an open-source machine
f8deb5b9 Poul Sander 2022-01-15 13:55 375
  learning library
f8deb5b9 Poul Sander 2022-01-15 13:55 376
f8deb5b9 Poul Sander 2022-01-15 13:55 377
* `quasardb <https://www.quasardb.net/>`_: a distributed, high-performance,
f8deb5b9 Poul Sander 2022-01-15 13:55 378
  associative database
f8deb5b9 Poul Sander 2022-01-15 13:55 379
  
f8deb5b9 Poul Sander 2022-01-15 13:55 380
* `Quill <https://github.com/odygrd/quill>`_: asynchronous low-latency logging library
f8deb5b9 Poul Sander 2022-01-15 13:55 381
f8deb5b9 Poul Sander 2022-01-15 13:55 382
* `QKW <https://github.com/ravijanjam/qkw>`_: generalizing aliasing to simplify
f8deb5b9 Poul Sander 2022-01-15 13:55 383
  navigation, and executing complex multi-line terminal command sequences
f8deb5b9 Poul Sander 2022-01-15 13:55 384
f8deb5b9 Poul Sander 2022-01-15 13:55 385
* `redis-cerberus <https://github.com/HunanTV/redis-cerberus>`_: a Redis cluster
f8deb5b9 Poul Sander 2022-01-15 13:55 386
  proxy
f8deb5b9 Poul Sander 2022-01-15 13:55 387
f8deb5b9 Poul Sander 2022-01-15 13:55 388
* `redpanda <https://vectorized.io/redpanda>`_: a 10x faster Kafka® replacement
f8deb5b9 Poul Sander 2022-01-15 13:55 389
  for mission critical systems written in C++
f8deb5b9 Poul Sander 2022-01-15 13:55 390
f8deb5b9 Poul Sander 2022-01-15 13:55 391
* `rpclib <http://rpclib.net/>`_: a modern C++ msgpack-RPC server and client
f8deb5b9 Poul Sander 2022-01-15 13:55 392
  library
f8deb5b9 Poul Sander 2022-01-15 13:55 393
f8deb5b9 Poul Sander 2022-01-15 13:55 394
* `Salesforce Analytics Cloud
f8deb5b9 Poul Sander 2022-01-15 13:55 395
  <https://www.salesforce.com/analytics-cloud/overview/>`_:
f8deb5b9 Poul Sander 2022-01-15 13:55 396
  business intelligence software
f8deb5b9 Poul Sander 2022-01-15 13:55 397
f8deb5b9 Poul Sander 2022-01-15 13:55 398
* `Scylla <https://www.scylladb.com/>`_: a Cassandra-compatible NoSQL data store
f8deb5b9 Poul Sander 2022-01-15 13:55 399
  that can handle 1 million transactions per second on a single server
f8deb5b9 Poul Sander 2022-01-15 13:55 400
f8deb5b9 Poul Sander 2022-01-15 13:55 401
* `Seastar <http://www.seastar-project.org/>`_: an advanced, open-source C++
f8deb5b9 Poul Sander 2022-01-15 13:55 402
  framework for high-performance server applications on modern hardware
f8deb5b9 Poul Sander 2022-01-15 13:55 403
f8deb5b9 Poul Sander 2022-01-15 13:55 404
* `spdlog <https://github.com/gabime/spdlog>`_: super fast C++ logging library
f8deb5b9 Poul Sander 2022-01-15 13:55 405
f8deb5b9 Poul Sander 2022-01-15 13:55 406
* `Stellar <https://www.stellar.org/>`_: financial platform
f8deb5b9 Poul Sander 2022-01-15 13:55 407
f8deb5b9 Poul Sander 2022-01-15 13:55 408
* `Touch Surgery <https://www.touchsurgery.com/>`_: surgery simulator
f8deb5b9 Poul Sander 2022-01-15 13:55 409
f8deb5b9 Poul Sander 2022-01-15 13:55 410
* `TrinityCore <https://github.com/TrinityCore/TrinityCore>`_: open-source
f8deb5b9 Poul Sander 2022-01-15 13:55 411
  MMORPG framework
f8deb5b9 Poul Sander 2022-01-15 13:55 412
f8deb5b9 Poul Sander 2022-01-15 13:55 413
* `Windows Terminal <https://github.com/microsoft/terminal>`_: the new Windows
f8deb5b9 Poul Sander 2022-01-15 13:55 414
  terminal
f8deb5b9 Poul Sander 2022-01-15 13:55 415
f8deb5b9 Poul Sander 2022-01-15 13:55 416
`More... <https://github.com/search?q=fmtlib&type=Code>`_
f8deb5b9 Poul Sander 2022-01-15 13:55 417
f8deb5b9 Poul Sander 2022-01-15 13:55 418
If you are aware of other projects using this library, please let me know
f8deb5b9 Poul Sander 2022-01-15 13:55 419
by `email <mailto:victor.zverovich@gmail.com>`_ or by submitting an
f8deb5b9 Poul Sander 2022-01-15 13:55 420
`issue <https://github.com/fmtlib/fmt/issues>`_.
f8deb5b9 Poul Sander 2022-01-15 13:55 421
f8deb5b9 Poul Sander 2022-01-15 13:55 422
Motivation
f8deb5b9 Poul Sander 2022-01-15 13:55 423
----------
f8deb5b9 Poul Sander 2022-01-15 13:55 424
f8deb5b9 Poul Sander 2022-01-15 13:55 425
So why yet another formatting library?
f8deb5b9 Poul Sander 2022-01-15 13:55 426
f8deb5b9 Poul Sander 2022-01-15 13:55 427
There are plenty of methods for doing this task, from standard ones like
f8deb5b9 Poul Sander 2022-01-15 13:55 428
the printf family of function and iostreams to Boost Format and FastFormat
f8deb5b9 Poul Sander 2022-01-15 13:55 429
libraries. The reason for creating a new library is that every existing
f8deb5b9 Poul Sander 2022-01-15 13:55 430
solution that I found either had serious issues or didn't provide
f8deb5b9 Poul Sander 2022-01-15 13:55 431
all the features I needed.
f8deb5b9 Poul Sander 2022-01-15 13:55 432
f8deb5b9 Poul Sander 2022-01-15 13:55 433
printf
f8deb5b9 Poul Sander 2022-01-15 13:55 434
~~~~~~
f8deb5b9 Poul Sander 2022-01-15 13:55 435
f8deb5b9 Poul Sander 2022-01-15 13:55 436
The good thing about ``printf`` is that it is pretty fast and readily available
f8deb5b9 Poul Sander 2022-01-15 13:55 437
being a part of the C standard library. The main drawback is that it
f8deb5b9 Poul Sander 2022-01-15 13:55 438
doesn't support user-defined types. ``printf`` also has safety issues although
f8deb5b9 Poul Sander 2022-01-15 13:55 439
they are somewhat mitigated with `__attribute__ ((format (printf, ...))
f8deb5b9 Poul Sander 2022-01-15 13:55 440
<https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html>`_ in GCC.
f8deb5b9 Poul Sander 2022-01-15 13:55 441
There is a POSIX extension that adds positional arguments required for
f8deb5b9 Poul Sander 2022-01-15 13:55 442
`i18n <https://en.wikipedia.org/wiki/Internationalization_and_localization>`_
f8deb5b9 Poul Sander 2022-01-15 13:55 443
to ``printf`` but it is not a part of C99 and may not be available on some
f8deb5b9 Poul Sander 2022-01-15 13:55 444
platforms.
f8deb5b9 Poul Sander 2022-01-15 13:55 445
f8deb5b9 Poul Sander 2022-01-15 13:55 446
iostreams
f8deb5b9 Poul Sander 2022-01-15 13:55 447
~~~~~~~~~
f8deb5b9 Poul Sander 2022-01-15 13:55 448
f8deb5b9 Poul Sander 2022-01-15 13:55 449
The main issue with iostreams is best illustrated with an example:
f8deb5b9 Poul Sander 2022-01-15 13:55 450
f8deb5b9 Poul Sander 2022-01-15 13:55 451
.. code:: c++
f8deb5b9 Poul Sander 2022-01-15 13:55 452
f8deb5b9 Poul Sander 2022-01-15 13:55 453
    std::cout << std::setprecision(2) << std::fixed << 1.23456 << "\n";
f8deb5b9 Poul Sander 2022-01-15 13:55 454
f8deb5b9 Poul Sander 2022-01-15 13:55 455
which is a lot of typing compared to printf:
f8deb5b9 Poul Sander 2022-01-15 13:55 456
f8deb5b9 Poul Sander 2022-01-15 13:55 457
.. code:: c++
f8deb5b9 Poul Sander 2022-01-15 13:55 458
f8deb5b9 Poul Sander 2022-01-15 13:55 459
    printf("%.2f\n", 1.23456);
f8deb5b9 Poul Sander 2022-01-15 13:55 460
f8deb5b9 Poul Sander 2022-01-15 13:55 461
Matthew Wilson, the author of FastFormat, called this "chevron hell". iostreams
f8deb5b9 Poul Sander 2022-01-15 13:55 462
don't support positional arguments by design.
f8deb5b9 Poul Sander 2022-01-15 13:55 463
f8deb5b9 Poul Sander 2022-01-15 13:55 464
The good part is that iostreams support user-defined types and are safe although
f8deb5b9 Poul Sander 2022-01-15 13:55 465
error handling is awkward.
f8deb5b9 Poul Sander 2022-01-15 13:55 466
f8deb5b9 Poul Sander 2022-01-15 13:55 467
Boost Format
f8deb5b9 Poul Sander 2022-01-15 13:55 468
~~~~~~~~~~~~
f8deb5b9 Poul Sander 2022-01-15 13:55 469
f8deb5b9 Poul Sander 2022-01-15 13:55 470
This is a very powerful library which supports both ``printf``-like format
f8deb5b9 Poul Sander 2022-01-15 13:55 471
strings and positional arguments. Its main drawback is performance. According to
f8deb5b9 Poul Sander 2022-01-15 13:55 472
various benchmarks, it is much slower than other methods considered here. Boost
f8deb5b9 Poul Sander 2022-01-15 13:55 473
Format also has excessive build times and severe code bloat issues (see
f8deb5b9 Poul Sander 2022-01-15 13:55 474
`Benchmarks`_).
f8deb5b9 Poul Sander 2022-01-15 13:55 475
f8deb5b9 Poul Sander 2022-01-15 13:55 476
FastFormat
f8deb5b9 Poul Sander 2022-01-15 13:55 477
~~~~~~~~~~
f8deb5b9 Poul Sander 2022-01-15 13:55 478
f8deb5b9 Poul Sander 2022-01-15 13:55 479
This is an interesting library which is fast, safe and has positional arguments.
f8deb5b9 Poul Sander 2022-01-15 13:55 480
However, it has significant limitations, citing its author:
f8deb5b9 Poul Sander 2022-01-15 13:55 481
f8deb5b9 Poul Sander 2022-01-15 13:55 482
    Three features that have no hope of being accommodated within the
f8deb5b9 Poul Sander 2022-01-15 13:55 483
    current design are:
f8deb5b9 Poul Sander 2022-01-15 13:55 484
f8deb5b9 Poul Sander 2022-01-15 13:55 485
    * Leading zeros (or any other non-space padding)
f8deb5b9 Poul Sander 2022-01-15 13:55 486
    * Octal/hexadecimal encoding
f8deb5b9 Poul Sander 2022-01-15 13:55 487
    * Runtime width/alignment specification
f8deb5b9 Poul Sander 2022-01-15 13:55 488
f8deb5b9 Poul Sander 2022-01-15 13:55 489
It is also quite big and has a heavy dependency, STLSoft, which might be too
f8deb5b9 Poul Sander 2022-01-15 13:55 490
restrictive for using it in some projects.
f8deb5b9 Poul Sander 2022-01-15 13:55 491
f8deb5b9 Poul Sander 2022-01-15 13:55 492
Boost Spirit.Karma
f8deb5b9 Poul Sander 2022-01-15 13:55 493
~~~~~~~~~~~~~~~~~~
f8deb5b9 Poul Sander 2022-01-15 13:55 494
f8deb5b9 Poul Sander 2022-01-15 13:55 495
This is not really a formatting library but I decided to include it here for
f8deb5b9 Poul Sander 2022-01-15 13:55 496
completeness. As iostreams, it suffers from the problem of mixing verbatim text
f8deb5b9 Poul Sander 2022-01-15 13:55 497
with arguments. The library is pretty fast, but slower on integer formatting
f8deb5b9 Poul Sander 2022-01-15 13:55 498
than ``fmt::format_to`` with format string compilation on Karma's own benchmark,
f8deb5b9 Poul Sander 2022-01-15 13:55 499
see `Converting a hundred million integers to strings per second
f8deb5b9 Poul Sander 2022-01-15 13:55 500
<http://www.zverovich.net/2020/06/13/fast-int-to-string-revisited.html>`_.
f8deb5b9 Poul Sander 2022-01-15 13:55 501
f8deb5b9 Poul Sander 2022-01-15 13:55 502
License
f8deb5b9 Poul Sander 2022-01-15 13:55 503
-------
f8deb5b9 Poul Sander 2022-01-15 13:55 504
f8deb5b9 Poul Sander 2022-01-15 13:55 505
{fmt} is distributed under the MIT `license
f8deb5b9 Poul Sander 2022-01-15 13:55 506
<https://github.com/fmtlib/fmt/blob/master/LICENSE.rst>`_.
f8deb5b9 Poul Sander 2022-01-15 13:55 507
f8deb5b9 Poul Sander 2022-01-15 13:55 508
Documentation License
f8deb5b9 Poul Sander 2022-01-15 13:55 509
---------------------
f8deb5b9 Poul Sander 2022-01-15 13:55 510
f8deb5b9 Poul Sander 2022-01-15 13:55 511
The `Format String Syntax <https://fmt.dev/latest/syntax.html>`_
f8deb5b9 Poul Sander 2022-01-15 13:55 512
section in the documentation is based on the one from Python `string module
f8deb5b9 Poul Sander 2022-01-15 13:55 513
documentation <https://docs.python.org/3/library/string.html#module-string>`_.
f8deb5b9 Poul Sander 2022-01-15 13:55 514
For this reason the documentation is distributed under the Python Software
f8deb5b9 Poul Sander 2022-01-15 13:55 515
Foundation license available in `doc/python-license.txt
f8deb5b9 Poul Sander 2022-01-15 13:55 516
<https://raw.github.com/fmtlib/fmt/master/doc/python-license.txt>`_.
f8deb5b9 Poul Sander 2022-01-15 13:55 517
It only applies if you distribute the documentation of {fmt}.
f8deb5b9 Poul Sander 2022-01-15 13:55 518
f8deb5b9 Poul Sander 2022-01-15 13:55 519
Maintainers
f8deb5b9 Poul Sander 2022-01-15 13:55 520
-----------
f8deb5b9 Poul Sander 2022-01-15 13:55 521
f8deb5b9 Poul Sander 2022-01-15 13:55 522
The {fmt} library is maintained by Victor Zverovich (`vitaut
f8deb5b9 Poul Sander 2022-01-15 13:55 523
<https://github.com/vitaut>`_) and Jonathan Müller (`foonathan
f8deb5b9 Poul Sander 2022-01-15 13:55 524
<https://github.com/foonathan>`_) with contributions from many other people.
f8deb5b9 Poul Sander 2022-01-15 13:55 525
See `Contributors <https://github.com/fmtlib/fmt/graphs/contributors>`_ and
f8deb5b9 Poul Sander 2022-01-15 13:55 526
`Releases <https://github.com/fmtlib/fmt/releases>`_ for some of the names.
f8deb5b9 Poul Sander 2022-01-15 13:55 527
Let us know if your contribution is not listed or mentioned incorrectly and
f8deb5b9 Poul Sander 2022-01-15 13:55 528
we'll make it right.
1970-01-01 00:00 529