git repos / blockattack-game

blame: source/misc/embedded_libs/fmt-11.0.2/doc/index.md

normal view · raw

47fd5c32 Poul Sander 2024-10-05 08:44 1
---
47fd5c32 Poul Sander 2024-10-05 08:44 2
hide:
47fd5c32 Poul Sander 2024-10-05 08:44 3
  - navigation
47fd5c32 Poul Sander 2024-10-05 08:44 4
  - toc
47fd5c32 Poul Sander 2024-10-05 08:44 5
---
47fd5c32 Poul Sander 2024-10-05 08:44 6
47fd5c32 Poul Sander 2024-10-05 08:44 7
# A modern formatting library
47fd5c32 Poul Sander 2024-10-05 08:44 8
47fd5c32 Poul Sander 2024-10-05 08:44 9
<div class="features-container">
47fd5c32 Poul Sander 2024-10-05 08:44 10
47fd5c32 Poul Sander 2024-10-05 08:44 11
<div class="feature">
47fd5c32 Poul Sander 2024-10-05 08:44 12
<h2>Safety</h2>
47fd5c32 Poul Sander 2024-10-05 08:44 13
<p>
47fd5c32 Poul Sander 2024-10-05 08:44 14
  Inspired by Python's formatting facility, {fmt} provides a safe replacement
47fd5c32 Poul Sander 2024-10-05 08:44 15
  for the <code>printf</code> family of functions. Errors in format strings,
47fd5c32 Poul Sander 2024-10-05 08:44 16
  which are a common source of vulnerabilities in C, are <b>reported at
47fd5c32 Poul Sander 2024-10-05 08:44 17
  compile time</b>. For example:
47fd5c32 Poul Sander 2024-10-05 08:44 18
47fd5c32 Poul Sander 2024-10-05 08:44 19
  <pre><code class="language-cpp"
47fd5c32 Poul Sander 2024-10-05 08:44 20
  >fmt::format("{:d}", "I am not a number");</code></pre>
47fd5c32 Poul Sander 2024-10-05 08:44 21
47fd5c32 Poul Sander 2024-10-05 08:44 22
  will give a compile-time error because <code>d</code> is not a valid
47fd5c32 Poul Sander 2024-10-05 08:44 23
  format specifier for strings. APIs like <a href="api/#format">
47fd5c32 Poul Sander 2024-10-05 08:44 24
  <code>fmt::format</code></a> <b>prevent buffer overflow errors</b> via
47fd5c32 Poul Sander 2024-10-05 08:44 25
  automatic memory management.
47fd5c32 Poul Sander 2024-10-05 08:44 26
</p>
47fd5c32 Poul Sander 2024-10-05 08:44 27
<a href="api#compile-time-checks">→ Learn more</a>
47fd5c32 Poul Sander 2024-10-05 08:44 28
</div>
47fd5c32 Poul Sander 2024-10-05 08:44 29
47fd5c32 Poul Sander 2024-10-05 08:44 30
<div class="feature">
47fd5c32 Poul Sander 2024-10-05 08:44 31
<h2>Extensibility</h2>
47fd5c32 Poul Sander 2024-10-05 08:44 32
<p>
47fd5c32 Poul Sander 2024-10-05 08:44 33
  Formatting of most <b>standard types</b>, including all containers, dates,
47fd5c32 Poul Sander 2024-10-05 08:44 34
  and times is <b>supported out-of-the-box</b>. For example:
47fd5c32 Poul Sander 2024-10-05 08:44 35
  
47fd5c32 Poul Sander 2024-10-05 08:44 36
  <pre><code class="language-cpp"
47fd5c32 Poul Sander 2024-10-05 08:44 37
  >fmt::print("{}", std::vector{1, 2, 3});</code></pre>
47fd5c32 Poul Sander 2024-10-05 08:44 38
47fd5c32 Poul Sander 2024-10-05 08:44 39
  prints the vector in a JSON-like format:
47fd5c32 Poul Sander 2024-10-05 08:44 40
47fd5c32 Poul Sander 2024-10-05 08:44 41
  <pre><code>[1, 2, 3]</code></pre>
47fd5c32 Poul Sander 2024-10-05 08:44 42
47fd5c32 Poul Sander 2024-10-05 08:44 43
  You can <b>make your own types formattable</b> and even make compile-time
47fd5c32 Poul Sander 2024-10-05 08:44 44
  checks work for them.
47fd5c32 Poul Sander 2024-10-05 08:44 45
</p>
47fd5c32 Poul Sander 2024-10-05 08:44 46
<a href="api#udt">→ Learn more</a>
47fd5c32 Poul Sander 2024-10-05 08:44 47
</div>
47fd5c32 Poul Sander 2024-10-05 08:44 48
47fd5c32 Poul Sander 2024-10-05 08:44 49
<div class="feature">
47fd5c32 Poul Sander 2024-10-05 08:44 50
<h2>Performance</h2>
47fd5c32 Poul Sander 2024-10-05 08:44 51
<p>
47fd5c32 Poul Sander 2024-10-05 08:44 52
  {fmt} can be anywhere from <b>tens of percent to 20-30 times faster</b> than
47fd5c32 Poul Sander 2024-10-05 08:44 53
  iostreams and <code>sprintf</code>, especially for numeric formatting.
47fd5c32 Poul Sander 2024-10-05 08:44 54
47fd5c32 Poul Sander 2024-10-05 08:44 55
<a href="https://github.com/fmtlib/fmt?tab=readme-ov-file#benchmarks">
47fd5c32 Poul Sander 2024-10-05 08:44 56
<img src="perf.svg">
47fd5c32 Poul Sander 2024-10-05 08:44 57
</a>
47fd5c32 Poul Sander 2024-10-05 08:44 58
47fd5c32 Poul Sander 2024-10-05 08:44 59
  The library <b>minimizes dynamic memory allocations</b> and can optionally
47fd5c32 Poul Sander 2024-10-05 08:44 60
  <a href="api#compile-api">compile format strings</a> to optimal code.
47fd5c32 Poul Sander 2024-10-05 08:44 61
</p>
47fd5c32 Poul Sander 2024-10-05 08:44 62
</div>
47fd5c32 Poul Sander 2024-10-05 08:44 63
47fd5c32 Poul Sander 2024-10-05 08:44 64
<div class="feature">
47fd5c32 Poul Sander 2024-10-05 08:44 65
<h2>Unicode support</h2>
47fd5c32 Poul Sander 2024-10-05 08:44 66
<p>
47fd5c32 Poul Sander 2024-10-05 08:44 67
  {fmt} provides <b>portable Unicode support</b> on major operating systems
47fd5c32 Poul Sander 2024-10-05 08:44 68
  with UTF-8 and <code>char</code> strings. For example:
47fd5c32 Poul Sander 2024-10-05 08:44 69
47fd5c32 Poul Sander 2024-10-05 08:44 70
  <pre><code class="language-cpp"
47fd5c32 Poul Sander 2024-10-05 08:44 71
  >fmt::print("Слава Україні!");</code></pre>
47fd5c32 Poul Sander 2024-10-05 08:44 72
47fd5c32 Poul Sander 2024-10-05 08:44 73
  will be printed correctly on Linux, macOS, and even Windows console,
47fd5c32 Poul Sander 2024-10-05 08:44 74
  irrespective of the codepages.
47fd5c32 Poul Sander 2024-10-05 08:44 75
</p>
47fd5c32 Poul Sander 2024-10-05 08:44 76
<p>
47fd5c32 Poul Sander 2024-10-05 08:44 77
  The default is <b>locale-independent</b>, but you can opt into localized
47fd5c32 Poul Sander 2024-10-05 08:44 78
  formatting and {fmt} makes it work with Unicode, addressing issues in the
47fd5c32 Poul Sander 2024-10-05 08:44 79
  standard libary.
47fd5c32 Poul Sander 2024-10-05 08:44 80
</p>
47fd5c32 Poul Sander 2024-10-05 08:44 81
</div>
47fd5c32 Poul Sander 2024-10-05 08:44 82
47fd5c32 Poul Sander 2024-10-05 08:44 83
<div class="feature">
47fd5c32 Poul Sander 2024-10-05 08:44 84
<h2>Fast compilation</h2>
47fd5c32 Poul Sander 2024-10-05 08:44 85
<p>
47fd5c32 Poul Sander 2024-10-05 08:44 86
  The library makes extensive use of <b>type erasure</b> to achieve fast
47fd5c32 Poul Sander 2024-10-05 08:44 87
  compilation. <code>fmt/base.h</code> provides a subset of the API with
47fd5c32 Poul Sander 2024-10-05 08:44 88
  <b>minimal include dependencies</b> and enough functionality to replace
47fd5c32 Poul Sander 2024-10-05 08:44 89
  all uses of <code>*printf</code>.
47fd5c32 Poul Sander 2024-10-05 08:44 90
</p>
47fd5c32 Poul Sander 2024-10-05 08:44 91
<p>
47fd5c32 Poul Sander 2024-10-05 08:44 92
  Code using {fmt} is usually several times faster to compile than the
47fd5c32 Poul Sander 2024-10-05 08:44 93
  equivalent iostreams code, and while <code>printf</code> compiles faster
47fd5c32 Poul Sander 2024-10-05 08:44 94
  still, the gap is narrowing.
47fd5c32 Poul Sander 2024-10-05 08:44 95
</p>
47fd5c32 Poul Sander 2024-10-05 08:44 96
<a href=
47fd5c32 Poul Sander 2024-10-05 08:44 97
"https://github.com/fmtlib/fmt?tab=readme-ov-file#compile-time-and-code-bloat">
47fd5c32 Poul Sander 2024-10-05 08:44 98
→ Learn more</a>
47fd5c32 Poul Sander 2024-10-05 08:44 99
</div>
47fd5c32 Poul Sander 2024-10-05 08:44 100
47fd5c32 Poul Sander 2024-10-05 08:44 101
<div class="feature">
47fd5c32 Poul Sander 2024-10-05 08:44 102
<h2>Small binary footprint</h2>
47fd5c32 Poul Sander 2024-10-05 08:44 103
<p>
47fd5c32 Poul Sander 2024-10-05 08:44 104
  Type erasure is also used to prevent template bloat, resulting in <b>compact
47fd5c32 Poul Sander 2024-10-05 08:44 105
  per-call binary code</b>. For example, a call to <code>fmt::print</code> with
47fd5c32 Poul Sander 2024-10-05 08:44 106
  a single argument is just <a href="https://godbolt.org/g/TZU4KF">a few
47fd5c32 Poul Sander 2024-10-05 08:44 107
  instructions</a>, comparable to <code>printf</code> despite adding
47fd5c32 Poul Sander 2024-10-05 08:44 108
  runtime safety, and much smaller than the equivalent iostreams code.
47fd5c32 Poul Sander 2024-10-05 08:44 109
</p>
47fd5c32 Poul Sander 2024-10-05 08:44 110
<p>
47fd5c32 Poul Sander 2024-10-05 08:44 111
  The library itself has small binary footprint and some components such as
47fd5c32 Poul Sander 2024-10-05 08:44 112
  floating-point formatting can be disabled to make it even smaller for
47fd5c32 Poul Sander 2024-10-05 08:44 113
  resource-constrained devices.
47fd5c32 Poul Sander 2024-10-05 08:44 114
</p>
47fd5c32 Poul Sander 2024-10-05 08:44 115
</div>
47fd5c32 Poul Sander 2024-10-05 08:44 116
47fd5c32 Poul Sander 2024-10-05 08:44 117
<div class="feature">
47fd5c32 Poul Sander 2024-10-05 08:44 118
<h2>Portability</h2>
47fd5c32 Poul Sander 2024-10-05 08:44 119
<p>
47fd5c32 Poul Sander 2024-10-05 08:44 120
  {fmt} has a <b>small self-contained codebase</b> with the core consisting of
47fd5c32 Poul Sander 2024-10-05 08:44 121
  just three headers and no external dependencies.
47fd5c32 Poul Sander 2024-10-05 08:44 122
</p>
47fd5c32 Poul Sander 2024-10-05 08:44 123
<p>
47fd5c32 Poul Sander 2024-10-05 08:44 124
  The library is highly portable and requires only a minimal <b>subset of
47fd5c32 Poul Sander 2024-10-05 08:44 125
  C++11</b> features which are available in GCC 4.8, Clang 3.4, MSVC 19.0
47fd5c32 Poul Sander 2024-10-05 08:44 126
  (2015) and later. Newer compiler and standard library features are used
47fd5c32 Poul Sander 2024-10-05 08:44 127
  if available, and enable additional functionality.
47fd5c32 Poul Sander 2024-10-05 08:44 128
</p>
47fd5c32 Poul Sander 2024-10-05 08:44 129
<p>
47fd5c32 Poul Sander 2024-10-05 08:44 130
  Where possible, the output of formatting functions is <b>consistent across
47fd5c32 Poul Sander 2024-10-05 08:44 131
  platforms</b>.
47fd5c32 Poul Sander 2024-10-05 08:44 132
</p>
47fd5c32 Poul Sander 2024-10-05 08:44 133
</p>
47fd5c32 Poul Sander 2024-10-05 08:44 134
</div>
47fd5c32 Poul Sander 2024-10-05 08:44 135
47fd5c32 Poul Sander 2024-10-05 08:44 136
<div class="feature">
47fd5c32 Poul Sander 2024-10-05 08:44 137
<h2>Open source</h2>
47fd5c32 Poul Sander 2024-10-05 08:44 138
<p>
47fd5c32 Poul Sander 2024-10-05 08:44 139
  {fmt} is in the top hundred open-source C++ libraries on GitHub and has
47fd5c32 Poul Sander 2024-10-05 08:44 140
  <a href="https://github.com/fmtlib/fmt/graphs/contributors">hundreds of
47fd5c32 Poul Sander 2024-10-05 08:44 141
  all-time contributors</a>.
47fd5c32 Poul Sander 2024-10-05 08:44 142
</p>
47fd5c32 Poul Sander 2024-10-05 08:44 143
<p>
47fd5c32 Poul Sander 2024-10-05 08:44 144
  The library is distributed under a permissive MIT
47fd5c32 Poul Sander 2024-10-05 08:44 145
  <a href="https://github.com/fmtlib/fmt#license">license</a> and is
47fd5c32 Poul Sander 2024-10-05 08:44 146
  <b>relied upon by many open-source projects</b>, including Blender, PyTorch,
47fd5c32 Poul Sander 2024-10-05 08:44 147
  Apple's FoundationDB, Windows Terminal, MongoDB, and others.
47fd5c32 Poul Sander 2024-10-05 08:44 148
</p>
47fd5c32 Poul Sander 2024-10-05 08:44 149
</div>
47fd5c32 Poul Sander 2024-10-05 08:44 150
47fd5c32 Poul Sander 2024-10-05 08:44 151
</div>
1970-01-01 00:00 152