Mercurial > minori
comparison dep/fmt/doc/html/index.html @ 343:1faa72660932
*: transfer back to cmake from autotools
autotools just made lots of things more complicated than
they should have and many things broke (i.e. translations)
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Thu, 20 Jun 2024 05:56:06 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
342:adb79bdde329 | 343:1faa72660932 |
---|---|
1 <!DOCTYPE html> | |
2 | |
3 | |
4 <html lang="en"> | |
5 <head> | |
6 <meta charset="utf-8"> | |
7 <meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
8 <meta name="viewport" content="width=device-width, initial-scale=1"> | |
9 | |
10 <meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> | |
11 | |
12 <title>Overview — fmt 10.2.1 documentation</title> | |
13 | |
14 <link rel="stylesheet" href="_static/basic.css" type="text/css" /> | |
15 <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> | |
16 <link rel="stylesheet" href="_static/breathe.css" type="text/css" /> | |
17 | |
18 <script type="text/javascript"> | |
19 var DOCUMENTATION_OPTIONS = { | |
20 URL_ROOT: './', | |
21 VERSION: '10.2.1', | |
22 COLLAPSE_INDEX: false, | |
23 FILE_SUFFIX: '.html', | |
24 LINK_SUFFIX: '.html', | |
25 SOURCELINK_SUFFIX: '.txt', | |
26 HAS_SOURCE: true, | |
27 SOURCELINK_SUFFIX: '.txt' | |
28 }; | |
29 </script> | |
30 <script src="_static/jquery.js"></script> | |
31 <script src="_static/underscore.js"></script> | |
32 <script src="_static/doctools.js"></script> | |
33 <script src="_static/language_data.js"></script> | |
34 <link rel="index" title="Index" href="genindex.html" /> | |
35 <link rel="search" title="Search" href="search.html" /> | |
36 <meta name="description" content="Small, safe and fast formatting library"> | |
37 <meta name="keywords" content="C++, formatting, printf, string, library"> | |
38 <meta name="author" content="Victor Zverovich"> | |
39 <link rel="stylesheet" href="_static/fmt.css"> | |
40 | |
41 <script async src="https://www.googletagmanager.com/gtag/js?id=UA-20116650-4"></script> | |
42 <script> | |
43 window.dataLayer = window.dataLayer || []; | |
44 function gtag(){dataLayer.push(arguments);} | |
45 gtag('js', new Date()); | |
46 | |
47 gtag('config', 'UA-20116650-4'); | |
48 </script> | |
49 | |
50 </head> | |
51 <body role="document"> | |
52 <nav class="navbar navbar-inverse"> | |
53 <div class="tb-container"> | |
54 <div class="row"> | |
55 <div class="navbar-content"> | |
56 | |
57 <div class="navbar-header"> | |
58 <button type="button" class="navbar-toggle collapsed" | |
59 data-toggle="collapse" data-target=".navbar-collapse"> | |
60 <span class="sr-only">Toggle navigation</span> | |
61 <span class="icon-bar"></span> | |
62 <span class="icon-bar"></span> | |
63 <span class="icon-bar"></span> | |
64 </button> | |
65 <a class="navbar-brand" href="index.html">{fmt}</a> | |
66 </div> | |
67 | |
68 | |
69 <div class="collapse navbar-collapse"> | |
70 <ul class="nav navbar-nav"> | |
71 <li class="dropdown"> | |
72 <a href="#" class="dropdown-toggle" data-toggle="dropdown" | |
73 role="button" aria-expanded="false">10.2.1 | |
74 <span class="caret"></span></a> | |
75 <ul class="dropdown-menu" role="menu"> | |
76 | |
77 <li><a href="https://fmt.dev/10.2.1">10.2.1</a></li> | |
78 | |
79 <li><a href="https://fmt.dev/10.2.0">10.2.0</a></li> | |
80 | |
81 <li><a href="https://fmt.dev/10.1.1">10.1.1</a></li> | |
82 | |
83 </ul> | |
84 </li> | |
85 | |
86 | |
87 <li><a href="contents.html">Contents</a></li> | |
88 | |
89 | |
90 | |
91 <li><a href="usage.html">Usage</a></li> | |
92 | |
93 | |
94 | |
95 <li><a href="api.html">API</a></li> | |
96 | |
97 | |
98 | |
99 <li><a href="syntax.html">Syntax</a></li> | |
100 | |
101 | |
102 </ul> | |
103 | |
104 | |
105 <form class="navbar-form navbar-right" role="search" action="search.html" | |
106 method="get"> | |
107 <div class="form-group"> | |
108 <input type="text" name="q" class="form-control" | |
109 placeholder="Search" > | |
110 </div> | |
111 <input type="hidden" name="check_keywords" value="yes" /> | |
112 <input type="hidden" name="area" value="default" /> | |
113 | |
114 </form> | |
115 | |
116 </div> | |
117 </div> | |
118 </div> | |
119 </div> | |
120 </nav> | |
121 | |
122 | |
123 <div class="jumbotron"> | |
124 <div class="tb-container"> | |
125 <h1>{fmt}</h1> | |
126 <p class="lead">A modern formatting library</p> | |
127 <div class="btn-group" role="group"> | |
128 | |
129 <a class="btn btn-success" | |
130 href="https://github.com/fmtlib/fmt/releases/download/10.2.1/fmt-10.2.1.zip"> | |
131 <span class="glyphicon glyphicon-download"></span> Download | |
132 </a> | |
133 <button type="button" class="btn btn-success dropdown-toggle" | |
134 data-toggle="dropdown"><span class="caret"></span></button> | |
135 <ul class="dropdown-menu"> | |
136 | |
137 | |
138 <li><a href="https://github.com/fmtlib/fmt/releases/download/10.2.1/fmt-10.2.1.zip">Version 10.2.1 | |
139 </a></li> | |
140 | |
141 | |
142 <li><a href="https://github.com/fmtlib/fmt/releases/download/10.2.0/fmt-10.2.0.zip">Version 10.2.0 | |
143 </a></li> | |
144 | |
145 | |
146 <li><a href="https://github.com/fmtlib/fmt/releases/download/10.1.1/fmt-10.1.1.zip">Version 10.1.1 | |
147 </a></li> | |
148 | |
149 </ul> | |
150 </div> | |
151 </div> | |
152 </div> | |
153 | |
154 | |
155 | |
156 <div class="tb-container"> | |
157 <div class="row"> | |
158 | |
159 | |
160 <div class="content"> | |
161 | |
162 <section id="overview"> | |
163 <h1>Overview<a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h1> | |
164 <p><strong>{fmt}</strong> is an open-source formatting library providing a fast and safe | |
165 alternative to C stdio and C++ iostreams.</p> | |
166 <div class="panel panel-default"> | |
167 <div class="panel-heading">What users say:</div> | |
168 <div class="panel-body"> | |
169 Thanks for creating this library. It’s been a hole in C++ for | |
170 a long time. I’ve used both <code>boost::format</code> and | |
171 <code>loki::SPrintf</code>, and neither felt like the right answer. | |
172 This does. | |
173 </div> | |
174 </div><section id="format-api"> | |
175 <span id="format-api-intro"></span><h2>Format API<a class="headerlink" href="#format-api" title="Permalink to this headline">¶</a></h2> | |
176 <p>The format API is similar in spirit to the C <code class="docutils literal notranslate"><span class="pre">printf</span></code> family of function but | |
177 is safer, simpler and several times <a class="reference external" href="https://www.zverovich.net/2020/06/13/fast-int-to-string-revisited.html">faster</a> | |
178 than common standard library implementations. | |
179 The <a class="reference external" href="syntax.html">format string syntax</a> is similar to the one used by | |
180 <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str.format">str.format</a> in | |
181 Python:</p> | |
182 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="w"> </span><span class="n">s</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">format</span><span class="p">(</span><span class="s">"The answer is {}."</span><span class="p">,</span><span class="w"> </span><span class="mi">42</span><span class="p">);</span> | |
183 </pre></div> | |
184 </div> | |
185 <p>The <code class="docutils literal notranslate"><span class="pre">fmt::format</span></code> function returns a string “The answer is 42.”. You can use | |
186 <code class="docutils literal notranslate"><span class="pre">fmt::memory_buffer</span></code> to avoid constructing <code class="docutils literal notranslate"><span class="pre">std::string</span></code>:</p> | |
187 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="k">auto</span><span class="w"> </span><span class="n">out</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">memory_buffer</span><span class="p">();</span> | |
188 <span class="n">fmt</span><span class="o">::</span><span class="n">format_to</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">back_inserter</span><span class="p">(</span><span class="n">out</span><span class="p">),</span> | |
189 <span class="w"> </span><span class="s">"For a moment, {} happened."</span><span class="p">,</span><span class="w"> </span><span class="s">"nothing"</span><span class="p">);</span> | |
190 <span class="k">auto</span><span class="w"> </span><span class="n">data</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">out</span><span class="p">.</span><span class="n">data</span><span class="p">();</span><span class="w"> </span><span class="c1">// pointer to the formatted data</span> | |
191 <span class="k">auto</span><span class="w"> </span><span class="n">size</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">out</span><span class="p">.</span><span class="n">size</span><span class="p">();</span><span class="w"> </span><span class="c1">// size of the formatted data</span> | |
192 </pre></div> | |
193 </div> | |
194 <p>The <code class="docutils literal notranslate"><span class="pre">fmt::print</span></code> function performs formatting and writes the result to a stream:</p> | |
195 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="n">fmt</span><span class="o">::</span><span class="n">print</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span><span class="w"> </span><span class="s">"System error code = {}</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="w"> </span><span class="n">errno</span><span class="p">);</span> | |
196 </pre></div> | |
197 </div> | |
198 <p>If you omit the file argument the function will print to <code class="docutils literal notranslate"><span class="pre">stdout</span></code>:</p> | |
199 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="n">fmt</span><span class="o">::</span><span class="n">print</span><span class="p">(</span><span class="s">"Don't {}</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="w"> </span><span class="s">"panic"</span><span class="p">);</span> | |
200 </pre></div> | |
201 </div> | |
202 <p>The format API also supports positional arguments useful for localization:</p> | |
203 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="n">fmt</span><span class="o">::</span><span class="n">print</span><span class="p">(</span><span class="s">"I'd rather be {1} than {0}."</span><span class="p">,</span><span class="w"> </span><span class="s">"right"</span><span class="p">,</span><span class="w"> </span><span class="s">"happy"</span><span class="p">);</span> | |
204 </pre></div> | |
205 </div> | |
206 <p>You can pass named arguments with <code class="docutils literal notranslate"><span class="pre">fmt::arg</span></code>:</p> | |
207 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="n">fmt</span><span class="o">::</span><span class="n">print</span><span class="p">(</span><span class="s">"Hello, {name}! The answer is {number}. Goodbye, {name}."</span><span class="p">,</span> | |
208 <span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">arg</span><span class="p">(</span><span class="s">"name"</span><span class="p">,</span><span class="w"> </span><span class="s">"World"</span><span class="p">),</span><span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">arg</span><span class="p">(</span><span class="s">"number"</span><span class="p">,</span><span class="w"> </span><span class="mi">42</span><span class="p">));</span> | |
209 </pre></div> | |
210 </div> | |
211 <p>If your compiler supports C++11 user-defined literals, the suffix <code class="docutils literal notranslate"><span class="pre">_a</span></code> offers | |
212 an alternative, slightly terser syntax for named arguments:</p> | |
213 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="k">using</span><span class="w"> </span><span class="k">namespace</span><span class="w"> </span><span class="nn">fmt</span><span class="o">::</span><span class="nn">literals</span><span class="p">;</span> | |
214 <span class="n">fmt</span><span class="o">::</span><span class="n">print</span><span class="p">(</span><span class="s">"Hello, {name}! The answer is {number}. Goodbye, {name}."</span><span class="p">,</span> | |
215 <span class="w"> </span><span class="s">"name"</span><span class="n">_a</span><span class="o">=</span><span class="s">"World"</span><span class="p">,</span><span class="w"> </span><span class="s">"number"</span><span class="n">_a</span><span class="o">=</span><span class="mi">42</span><span class="p">);</span> | |
216 </pre></div> | |
217 </div> | |
218 </section> | |
219 <section id="safety"> | |
220 <span id="id1"></span><h2>Safety<a class="headerlink" href="#safety" title="Permalink to this headline">¶</a></h2> | |
221 <p>The library is fully type safe, automatic memory management prevents buffer | |
222 overflow, errors in format strings are reported using exceptions or at compile | |
223 time. For example, the code</p> | |
224 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="n">fmt</span><span class="o">::</span><span class="n">format</span><span class="p">(</span><span class="s">"The answer is {:d}"</span><span class="p">,</span><span class="w"> </span><span class="s">"forty-two"</span><span class="p">);</span> | |
225 </pre></div> | |
226 </div> | |
227 <p>throws the <code class="docutils literal notranslate"><span class="pre">format_error</span></code> exception because the argument <code class="docutils literal notranslate"><span class="pre">"forty-two"</span></code> is a | |
228 string while the format code <code class="docutils literal notranslate"><span class="pre">d</span></code> only applies to integers.</p> | |
229 <p>The code</p> | |
230 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="n">format</span><span class="p">(</span><span class="n">FMT_STRING</span><span class="p">(</span><span class="s">"The answer is {:d}"</span><span class="p">),</span><span class="w"> </span><span class="s">"forty-two"</span><span class="p">);</span> | |
231 </pre></div> | |
232 </div> | |
233 <p>reports a compile-time error on compilers that support relaxed <code class="docutils literal notranslate"><span class="pre">constexpr</span></code>. | |
234 See <a class="reference external" href="api.html#compile-time-format-string-checks">here</a> for details.</p> | |
235 <p>The following code</p> | |
236 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span>fmt::format("Cyrillic letter {}", L'\x42e'); | |
237 </pre></div> | |
238 </div> | |
239 <p>produces a compile-time error because wide character <code class="docutils literal notranslate"><span class="pre">L'\x42e'</span></code> cannot be | |
240 formatted into a narrow string. For comparison, writing a wide character to | |
241 <code class="docutils literal notranslate"><span class="pre">std::ostream</span></code> results in its numeric value being written to the stream | |
242 (i.e. 1070 instead of letter ‘ю’ which is represented by <code class="docutils literal notranslate"><span class="pre">L'\x42e'</span></code> if we | |
243 use Unicode) which is rarely desirable.</p> | |
244 </section> | |
245 <section id="compact-binary-code"> | |
246 <h2>Compact Binary Code<a class="headerlink" href="#compact-binary-code" title="Permalink to this headline">¶</a></h2> | |
247 <p>The library produces compact per-call compiled code. For example | |
248 (<a class="reference external" href="https://godbolt.org/g/TZU4KF">godbolt</a>),</p> | |
249 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf"><fmt/core.h></span> | |
250 | |
251 <span class="kt">int</span><span class="w"> </span><span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span> | |
252 <span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">print</span><span class="p">(</span><span class="s">"The answer is {}."</span><span class="p">,</span><span class="w"> </span><span class="mi">42</span><span class="p">);</span> | |
253 <span class="p">}</span> | |
254 </pre></div> | |
255 </div> | |
256 <p>compiles to just</p> | |
257 <div class="highlight-asm notranslate"><div class="highlight"><pre><span></span>main: # @main | |
258 sub rsp, 24 | |
259 mov qword ptr [rsp], 42 | |
260 mov rcx, rsp | |
261 mov edi, offset .L.str | |
262 mov esi, 17 | |
263 mov edx, 1 | |
264 call fmt::v7::vprint(fmt::v7::basic_string_view<char>, fmt::v7::format_args) | |
265 xor eax, eax | |
266 add rsp, 24 | |
267 ret | |
268 .L.str: | |
269 .asciz "The answer is {}." | |
270 </pre></div> | |
271 </div> | |
272 </section> | |
273 <section id="portability"> | |
274 <span id="id2"></span><h2>Portability<a class="headerlink" href="#portability" title="Permalink to this headline">¶</a></h2> | |
275 <p>The library is highly portable and relies only on a small set of C++11 features:</p> | |
276 <ul class="simple"> | |
277 <li><p>variadic templates</p></li> | |
278 <li><p>type traits</p></li> | |
279 <li><p>rvalue references</p></li> | |
280 <li><p>decltype</p></li> | |
281 <li><p>trailing return types</p></li> | |
282 <li><p>deleted functions</p></li> | |
283 <li><p>alias templates</p></li> | |
284 </ul> | |
285 <p>These are available in GCC 4.8, Clang 3.4, MSVC 19.0 (2015) and more recent | |
286 compiler version. For older compilers use {fmt} <a class="reference external" href="https://github.com/fmtlib/fmt/releases/tag/4.1.0">version 4.x</a> which is maintained and | |
287 only requires C++98.</p> | |
288 <p>The output of all formatting functions is consistent across platforms. | |
289 For example,</p> | |
290 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="n">fmt</span><span class="o">::</span><span class="n">print</span><span class="p">(</span><span class="s">"{}"</span><span class="p">,</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">numeric_limits</span><span class="o"><</span><span class="kt">double</span><span class="o">>::</span><span class="n">infinity</span><span class="p">());</span> | |
291 </pre></div> | |
292 </div> | |
293 <p>always prints <code class="docutils literal notranslate"><span class="pre">inf</span></code> while the output of <code class="docutils literal notranslate"><span class="pre">printf</span></code> is platform-dependent.</p> | |
294 </section> | |
295 <section id="ease-of-use"> | |
296 <span id="id3"></span><h2>Ease of Use<a class="headerlink" href="#ease-of-use" title="Permalink to this headline">¶</a></h2> | |
297 <p>{fmt} has a small self-contained code base with the core library consisting of | |
298 just three header files and no external dependencies. | |
299 A permissive MIT <a class="reference external" href="https://github.com/fmtlib/fmt#license">license</a> allows | |
300 using the library both in open-source and commercial projects.</p> | |
301 <p><a class="reference external" href="contents.html">Learn more…</a></p> | |
302 <a class="btn btn-success" href="https://github.com/fmtlib/fmt">GitHub Repository</a> | |
303 | |
304 <div class="section footer"> | |
305 <iframe src="https://ghbtns.com/github-btn.html?user=fmtlib&repo=fmt&type=watch&count=true" | |
306 class="github-btn" width="100" height="20"></iframe> | |
307 </div></section> | |
308 </section> | |
309 | |
310 | |
311 </div> | |
312 </div> | |
313 </div> | |
314 | |
315 | |
316 | |
317 <div class="footer" role="contentinfo"> | |
318 © Copyright 2012-present, Victor Zverovich. | |
319 Created using <a href="http://sphinx-doc.org/">Sphinx</a> 3.3.0. | |
320 </div> | |
321 | |
322 <script src="_static/bootstrap.min.js"></script> | |
323 | |
324 </body> | |
325 </html> |