Mercurial > minori
comparison dep/fmt/doc/html/api.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>API Reference — 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 class="active"><a href="api.html">API | |
96 <span class="sr-only">(current)</span></a></li> | |
97 | |
98 | |
99 | |
100 <li><a href="syntax.html">Syntax</a></li> | |
101 | |
102 | |
103 </ul> | |
104 | |
105 | |
106 <form class="navbar-form navbar-right" role="search" action="search.html" | |
107 method="get"> | |
108 <div class="form-group"> | |
109 <input type="text" name="q" class="form-control" | |
110 placeholder="Search" > | |
111 </div> | |
112 <input type="hidden" name="check_keywords" value="yes" /> | |
113 <input type="hidden" name="area" value="default" /> | |
114 | |
115 </form> | |
116 | |
117 </div> | |
118 </div> | |
119 </div> | |
120 </div> | |
121 </nav> | |
122 | |
123 | |
124 | |
125 <div class="tb-container"> | |
126 <div class="row"> | |
127 | |
128 | |
129 <div class="content"> | |
130 | |
131 <section id="api-reference"> | |
132 <span id="string-formatting-api"></span><h1>API Reference<a class="headerlink" href="#api-reference" title="Permalink to this headline">¶</a></h1> | |
133 <p>The {fmt} library API consists of the following parts:</p> | |
134 <ul class="simple"> | |
135 <li><p><a class="reference internal" href="#core-api"><span class="std std-ref">fmt/core.h</span></a>: the core API providing main formatting functions | |
136 for <code class="docutils literal notranslate"><span class="pre">char</span></code>/UTF-8 with C++20 compile-time checks and minimal dependencies</p></li> | |
137 <li><p><a class="reference internal" href="#format-api"><span class="std std-ref">fmt/format.h</span></a>: the full format API providing additional | |
138 formatting functions and locale support</p></li> | |
139 <li><p><a class="reference internal" href="#ranges-api"><span class="std std-ref">fmt/ranges.h</span></a>: formatting of ranges and tuples</p></li> | |
140 <li><p><a class="reference internal" href="#chrono-api"><span class="std std-ref">fmt/chrono.h</span></a>: date and time formatting</p></li> | |
141 <li><p><a class="reference internal" href="#std-api"><span class="std std-ref">fmt/std.h</span></a>: formatters for standard library types</p></li> | |
142 <li><p><a class="reference internal" href="#compile-api"><span class="std std-ref">fmt/compile.h</span></a>: format string compilation</p></li> | |
143 <li><p><a class="reference internal" href="#color-api"><span class="std std-ref">fmt/color.h</span></a>: terminal color and text style</p></li> | |
144 <li><p><a class="reference internal" href="#os-api"><span class="std std-ref">fmt/os.h</span></a>: system APIs</p></li> | |
145 <li><p><a class="reference internal" href="#ostream-api"><span class="std std-ref">fmt/ostream.h</span></a>: <code class="docutils literal notranslate"><span class="pre">std::ostream</span></code> support</p></li> | |
146 <li><p><a class="reference internal" href="#args-api"><span class="std std-ref">fmt/args.h</span></a>: dynamic argument lists</p></li> | |
147 <li><p><a class="reference internal" href="#printf-api"><span class="std std-ref">fmt/printf.h</span></a>: <code class="docutils literal notranslate"><span class="pre">printf</span></code> formatting</p></li> | |
148 <li><p><a class="reference internal" href="#xchar-api"><span class="std std-ref">fmt/xchar.h</span></a>: optional <code class="docutils literal notranslate"><span class="pre">wchar_t</span></code> support</p></li> | |
149 </ul> | |
150 <p>All functions and types provided by the library reside in namespace <code class="docutils literal notranslate"><span class="pre">fmt</span></code> and | |
151 macros have prefix <code class="docutils literal notranslate"><span class="pre">FMT_</span></code>.</p> | |
152 <section id="core-api"> | |
153 <span id="id1"></span><h2>Core API<a class="headerlink" href="#core-api" title="Permalink to this headline">¶</a></h2> | |
154 <p><code class="docutils literal notranslate"><span class="pre">fmt/core.h</span></code> defines the core API which provides main formatting functions | |
155 for <code class="docutils literal notranslate"><span class="pre">char</span></code>/UTF-8 with C++20 compile-time checks. It has minimal include | |
156 dependencies for better compile times. This header is only beneficial when | |
157 using {fmt} as a library (the default) and not in the header-only mode. | |
158 It also provides <code class="docutils literal notranslate"><span class="pre">formatter</span></code> specializations for built-in and string types.</p> | |
159 <p>The following functions use <a class="reference internal" href="syntax.html#syntax"><span class="std std-ref">format string syntax</span></a> | |
160 similar to that of Python’s <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str.format">str.format</a>. | |
161 They take <em>fmt</em> and <em>args</em> as arguments.</p> | |
162 <p><em>fmt</em> is a format string that contains literal text and replacement fields | |
163 surrounded by braces <code class="docutils literal notranslate"><span class="pre">{}</span></code>. The fields are replaced with formatted arguments | |
164 in the resulting string. <a class="reference internal" href="#_CPPv4IDpEN3fmt13format_stringE" title="fmt::format_string"><code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">format_string</span></code></a> is a format string which can be | |
165 implicitly constructed from a string literal or a <code class="docutils literal notranslate"><span class="pre">constexpr</span></code> string and is | |
166 checked at compile time in C++20. To pass a runtime format string wrap it in | |
167 <a class="reference internal" href="#_CPPv4N3fmt7runtimeE11string_view" title="fmt::runtime"><code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">fmt::runtime()</span></code></a>.</p> | |
168 <p><em>args</em> is an argument list representing objects to be formatted.</p> | |
169 <p>I/O errors are reported as <a class="reference external" href="https://en.cppreference.com/w/cpp/error/system_error">std::system_error</a> exceptions unless | |
170 specified otherwise.</p> | |
171 <span class="target" id="format"></span><dl class="cpp function"> | |
172 <dt id="_CPPv4IDpEN3fmt6formatENSt6stringE13format_stringIDp1TEDpRR1T"> | |
173 <span id="_CPPv3IDpEN3fmt6formatE13format_stringIDp1TEDpRR1T"></span><span id="_CPPv2IDpEN3fmt6formatE13format_stringIDp1TEDpRR1T"></span>template<typename ...<code class="sig-name descname">T</code>><br /><span class="target" id="core_8h_1a6dd296c9100bdd4939538068b77bdfe1"></span>auto <code class="sig-prename descclassname"><a class="reference internal" href="#_CPPv4IDpEN3fmt6formatENSt6stringE13format_stringIDp1TEDpRR1T" title="fmt::format::fmt">fmt</a><code class="sig-prename descclassname">::</code></code><code class="sig-name descname">format</code><span class="sig-paren">(</span><a class="reference internal" href="#_CPPv4IDpEN3fmt13format_stringE" title="fmt::format_string">format_string</a><<a class="reference internal" href="#_CPPv4IDpEN3fmt6formatENSt6stringE13format_stringIDp1TEDpRR1T" title="fmt::format::T">T</a>...> <em>fmt</em>, <a class="reference internal" href="#_CPPv4IDpEN3fmt6formatENSt6stringE13format_stringIDp1TEDpRR1T" title="fmt::format::T">T</a>&&... <em>args</em><span class="sig-paren">)</span> -> std::string<a class="headerlink" href="#_CPPv4IDpEN3fmt6formatENSt6stringE13format_stringIDp1TEDpRR1T" title="Permalink to this definition">¶</a><br /></dt> | |
174 <dd><p><p><p>Formats <code class="docutils literal notranslate"><span class="pre">args</span></code> according to specifications in <code class="docutils literal notranslate"><span class="pre">fmt</span></code> and returns the result | |
175 as a string.</p> | |
176 <p><strong>Example</strong>:</p> | |
177 <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> | |
178 <span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="w"> </span><span class="n">message</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> | |
179 </pre></div> | |
180 </div> | |
181 </p> | |
182 </p> | |
183 </dd></dl> | |
184 | |
185 <dl class="cpp function"> | |
186 <dt id="_CPPv4N3fmt7vformatE11string_view11format_args"> | |
187 <span id="_CPPv3N3fmt7vformatE11string_view11format_args"></span><span id="_CPPv2N3fmt7vformatE11string_view11format_args"></span><span id="fmt::vformat__string_view.format_args"></span><span class="target" id="core_8h_1a3688aa4186696a1231623bde7775a953"></span>auto <code class="sig-prename descclassname"><a class="reference internal" href="#_CPPv4N3fmt7vformatE11string_view11format_args" title="fmt::vformat::fmt">fmt</a><code class="sig-prename descclassname">::</code></code><code class="sig-name descname">vformat</code><span class="sig-paren">(</span><a class="reference internal" href="#_CPPv4N3fmt11string_viewE" title="fmt::string_view">string_view</a> <em>fmt</em>, <a class="reference internal" href="#_CPPv4N3fmt11format_argsE" title="fmt::format_args">format_args</a> <em>args</em><span class="sig-paren">)</span> -> std::string<a class="headerlink" href="#_CPPv4N3fmt7vformatE11string_view11format_args" title="Permalink to this definition">¶</a><br /></dt> | |
188 <dd></dd></dl> | |
189 | |
190 <dl class="cpp function"> | |
191 <dt id="_CPPv4I0DpEN3fmt9format_toE8OutputIt8OutputIt13format_stringIDp1TEDpRR1T"> | |
192 <span id="_CPPv3I0DpEN3fmt9format_toE8OutputIt13format_stringIDp1TEDpRR1T"></span><span id="_CPPv2I0DpEN3fmt9format_toE8OutputIt13format_stringIDp1TEDpRR1T"></span>template<typename <code class="sig-name descname">OutputIt</code>, typename ...<code class="sig-name descname">T</code>><br /><span class="target" id="core_8h_1a0ca5ab5f03a0c86633550f1dd5744577"></span>auto <code class="sig-prename descclassname"><a class="reference internal" href="#_CPPv4I0DpEN3fmt9format_toE8OutputIt8OutputIt13format_stringIDp1TEDpRR1T" title="fmt::format_to::fmt">fmt</a><code class="sig-prename descclassname">::</code></code><code class="sig-name descname">format_to</code><span class="sig-paren">(</span><a class="reference internal" href="#_CPPv4I0DpEN3fmt9format_toE8OutputIt8OutputIt13format_stringIDp1TEDpRR1T" title="fmt::format_to::OutputIt">OutputIt</a> <em>out</em>, <a class="reference internal" href="#_CPPv4IDpEN3fmt13format_stringE" title="fmt::format_string">format_string</a><<a class="reference internal" href="#_CPPv4I0DpEN3fmt9format_toE8OutputIt8OutputIt13format_stringIDp1TEDpRR1T" title="fmt::format_to::T">T</a>...> <em>fmt</em>, <a class="reference internal" href="#_CPPv4I0DpEN3fmt9format_toE8OutputIt8OutputIt13format_stringIDp1TEDpRR1T" title="fmt::format_to::T">T</a>&&... <em>args</em><span class="sig-paren">)</span> -> <a class="reference internal" href="#_CPPv4I0DpEN3fmt9format_toE8OutputIt8OutputIt13format_stringIDp1TEDpRR1T" title="fmt::format_to::OutputIt">OutputIt</a><a class="headerlink" href="#_CPPv4I0DpEN3fmt9format_toE8OutputIt8OutputIt13format_stringIDp1TEDpRR1T" title="Permalink to this definition">¶</a><br /></dt> | |
193 <dd><p><p><p>Formats <code class="docutils literal notranslate"><span class="pre">args</span></code> according to specifications in <code class="docutils literal notranslate"><span class="pre">fmt</span></code>, writes the result to | |
194 the output iterator <code class="docutils literal notranslate"><span class="pre">out</span></code> and returns the iterator past the end of the output | |
195 range. <a class="reference internal" href="#_CPPv4I0DpEN3fmt9format_toE8OutputIt8OutputIt13format_stringIDp1TEDpRR1T" title="fmt::format_to"><code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">format_to()</span></code></a> does not append a terminating null character.</p> | |
196 <p><strong>Example</strong>:</p> | |
197 <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">std</span><span class="o">::</span><span class="n">vector</span><span class="o"><</span><span class="kt">char</span><span class="o">></span><span class="p">();</span> | |
198 <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><span class="w"> </span><span class="s">"{}"</span><span class="p">,</span><span class="w"> </span><span class="mi">42</span><span class="p">);</span> | |
199 </pre></div> | |
200 </div> | |
201 </p> | |
202 </p> | |
203 </dd></dl> | |
204 | |
205 <dl class="cpp function"> | |
206 <dt id="_CPPv4I0DpEN3fmt11format_to_nE18format_to_n_resultI8OutputItE8OutputIt6size_t13format_stringIDp1TEDpRR1T"> | |
207 <span id="_CPPv3I0DpEN3fmt11format_to_nE8OutputIt6size_t13format_stringIDp1TEDpRR1T"></span><span id="_CPPv2I0DpEN3fmt11format_to_nE8OutputIt6size_t13format_stringIDp1TEDpRR1T"></span>template<typename <code class="sig-name descname">OutputIt</code>, typename ...<code class="sig-name descname">T</code>><br /><span class="target" id="core_8h_1af2a17cefc40c6d780369144c5de1e2af"></span>auto <code class="sig-prename descclassname"><a class="reference internal" href="#_CPPv4I0DpEN3fmt11format_to_nE18format_to_n_resultI8OutputItE8OutputIt6size_t13format_stringIDp1TEDpRR1T" title="fmt::format_to_n::fmt">fmt</a><code class="sig-prename descclassname">::</code></code><code class="sig-name descname">format_to_n</code><span class="sig-paren">(</span><a class="reference internal" href="#_CPPv4I0DpEN3fmt11format_to_nE18format_to_n_resultI8OutputItE8OutputIt6size_t13format_stringIDp1TEDpRR1T" title="fmt::format_to_n::OutputIt">OutputIt</a> <em>out</em>, size_t <em>n</em>, <a class="reference internal" href="#_CPPv4IDpEN3fmt13format_stringE" title="fmt::format_string">format_string</a><<a class="reference internal" href="#_CPPv4I0DpEN3fmt11format_to_nE18format_to_n_resultI8OutputItE8OutputIt6size_t13format_stringIDp1TEDpRR1T" title="fmt::format_to_n::T">T</a>...> <em>fmt</em>, <a class="reference internal" href="#_CPPv4I0DpEN3fmt11format_to_nE18format_to_n_resultI8OutputItE8OutputIt6size_t13format_stringIDp1TEDpRR1T" title="fmt::format_to_n::T">T</a>&&... <em>args</em><span class="sig-paren">)</span> -> <a class="reference internal" href="#_CPPv4I0EN3fmt18format_to_n_resultE" title="fmt::format_to_n_result">format_to_n_result</a><<a class="reference internal" href="#_CPPv4I0DpEN3fmt11format_to_nE18format_to_n_resultI8OutputItE8OutputIt6size_t13format_stringIDp1TEDpRR1T" title="fmt::format_to_n::OutputIt">OutputIt</a>><a class="headerlink" href="#_CPPv4I0DpEN3fmt11format_to_nE18format_to_n_resultI8OutputItE8OutputIt6size_t13format_stringIDp1TEDpRR1T" title="Permalink to this definition">¶</a><br /></dt> | |
208 <dd><p><p><p>Formats <code class="docutils literal notranslate"><span class="pre">args</span></code> according to specifications in <code class="docutils literal notranslate"><span class="pre">fmt</span></code>, writes up to <code class="docutils literal notranslate"><span class="pre">n</span></code> | |
209 characters of the result to the output iterator <code class="docutils literal notranslate"><span class="pre">out</span></code> and returns the total | |
210 (not truncated) output size and the iterator past the end of the output range. | |
211 <a class="reference internal" href="#_CPPv4I0DpEN3fmt11format_to_nE18format_to_n_resultI8OutputItE8OutputIt6size_t13format_stringIDp1TEDpRR1T" title="fmt::format_to_n"><code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">format_to_n()</span></code></a> does not append a terminating null character.</p> | |
212 </p> | |
213 </p> | |
214 </dd></dl> | |
215 | |
216 <dl class="cpp function"> | |
217 <dt id="_CPPv4IDpEN3fmt14formatted_sizeE6size_t13format_stringIDp1TEDpRR1T"> | |
218 <span id="_CPPv3IDpEN3fmt14formatted_sizeE13format_stringIDp1TEDpRR1T"></span><span id="_CPPv2IDpEN3fmt14formatted_sizeE13format_stringIDp1TEDpRR1T"></span>template<typename ...<code class="sig-name descname">T</code>><br /><span class="target" id="core_8h_1a009f905ac9329b59e440fd4c2460d44c"></span>auto <code class="sig-prename descclassname"><a class="reference internal" href="#_CPPv4IDpEN3fmt14formatted_sizeE6size_t13format_stringIDp1TEDpRR1T" title="fmt::formatted_size::fmt">fmt</a><code class="sig-prename descclassname">::</code></code><code class="sig-name descname">formatted_size</code><span class="sig-paren">(</span><a class="reference internal" href="#_CPPv4IDpEN3fmt13format_stringE" title="fmt::format_string">format_string</a><<a class="reference internal" href="#_CPPv4IDpEN3fmt14formatted_sizeE6size_t13format_stringIDp1TEDpRR1T" title="fmt::formatted_size::T">T</a>...> <em>fmt</em>, <a class="reference internal" href="#_CPPv4IDpEN3fmt14formatted_sizeE6size_t13format_stringIDp1TEDpRR1T" title="fmt::formatted_size::T">T</a>&&... <em>args</em><span class="sig-paren">)</span> -> size_t<a class="headerlink" href="#_CPPv4IDpEN3fmt14formatted_sizeE6size_t13format_stringIDp1TEDpRR1T" title="Permalink to this definition">¶</a><br /></dt> | |
219 <dd><p>Returns the number of chars in the output of <code class="docutils literal notranslate"><span class="pre">format(fmt,</span> <span class="pre">args...)</span></code>. </p> | |
220 </dd></dl> | |
221 | |
222 <dl class="cpp struct"> | |
223 <dt id="_CPPv4I0EN3fmt18format_to_n_resultE"> | |
224 <span id="_CPPv3I0EN3fmt18format_to_n_resultE"></span><span id="_CPPv2I0EN3fmt18format_to_n_resultE"></span>template<typename <code class="sig-name descname">OutputIt</code>><br /><span class="target" id="structfmt_1_1format__to__n__result"></span><em class="property">struct </em><code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">format_to_n_result</code><a class="headerlink" href="#_CPPv4I0EN3fmt18format_to_n_resultE" title="Permalink to this definition">¶</a><br /></dt> | |
225 <dd><div class="breathe-sectiondef docutils container"> | |
226 <p class="breathe-sectiondef-title rubric">Public Members</p> | |
227 <dl class="cpp var"> | |
228 <dt id="_CPPv4N3fmt18format_to_n_result3outE"> | |
229 <span id="_CPPv3N3fmt18format_to_n_result3outE"></span><span id="_CPPv2N3fmt18format_to_n_result3outE"></span><span id="fmt::format_to_n_result::out__OutputIt"></span><span class="target" id="structfmt_1_1format__to__n__result_1a71d11006ad16fba226096f94c21b037e"></span><a class="reference internal" href="#_CPPv4I0EN3fmt18format_to_n_resultE" title="fmt::format_to_n_result::OutputIt">OutputIt</a> <code class="sig-name descname">out</code><a class="headerlink" href="#_CPPv4N3fmt18format_to_n_result3outE" title="Permalink to this definition">¶</a><br /></dt> | |
230 <dd><p>Iterator past the end of the output range. </p> | |
231 </dd></dl> | |
232 | |
233 <dl class="cpp var"> | |
234 <dt id="_CPPv4N3fmt18format_to_n_result4sizeE"> | |
235 <span id="_CPPv3N3fmt18format_to_n_result4sizeE"></span><span id="_CPPv2N3fmt18format_to_n_result4sizeE"></span><span id="fmt::format_to_n_result::size__s"></span><span class="target" id="structfmt_1_1format__to__n__result_1a2dd58f1d85be6662df6fdfd943aecc88"></span>size_t <code class="sig-name descname">size</code><a class="headerlink" href="#_CPPv4N3fmt18format_to_n_result4sizeE" title="Permalink to this definition">¶</a><br /></dt> | |
236 <dd><p>Total (not truncated) output size. </p> | |
237 </dd></dl> | |
238 | |
239 </div> | |
240 </dd></dl> | |
241 | |
242 <span class="target" id="print"></span><dl class="cpp function"> | |
243 <dt id="_CPPv4IDpEN3fmt5printEv13format_stringIDp1TEDpRR1T"> | |
244 <span id="_CPPv3IDpEN3fmt5printE13format_stringIDp1TEDpRR1T"></span><span id="_CPPv2IDpEN3fmt5printE13format_stringIDp1TEDpRR1T"></span>template<typename ...<code class="sig-name descname">T</code>><br /><span class="target" id="core_8h_1ac0252a192c582b07d6398e7df4f84ec7"></span>void <code class="sig-prename descclassname"><a class="reference internal" href="#_CPPv4IDpEN3fmt5printEv13format_stringIDp1TEDpRR1T" title="fmt::print::fmt">fmt</a><code class="sig-prename descclassname">::</code></code><code class="sig-name descname">print</code><span class="sig-paren">(</span><a class="reference internal" href="#_CPPv4IDpEN3fmt13format_stringE" title="fmt::format_string">format_string</a><<a class="reference internal" href="#_CPPv4IDpEN3fmt5printEv13format_stringIDp1TEDpRR1T" title="fmt::print::T">T</a>...> <em>fmt</em>, <a class="reference internal" href="#_CPPv4IDpEN3fmt5printEv13format_stringIDp1TEDpRR1T" title="fmt::print::T">T</a>&&... <em>args</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4IDpEN3fmt5printEv13format_stringIDp1TEDpRR1T" title="Permalink to this definition">¶</a><br /></dt> | |
245 <dd><p><p><p>Formats <code class="docutils literal notranslate"><span class="pre">args</span></code> according to specifications in <code class="docutils literal notranslate"><span class="pre">fmt</span></code> and writes the output | |
246 to <code class="docutils literal notranslate"><span class="pre">stdout</span></code>.</p> | |
247 <p><strong>Example</strong>:</p> | |
248 <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">"Elapsed time: {0:.2f} seconds"</span><span class="p">,</span><span class="w"> </span><span class="mf">1.23</span><span class="p">);</span> | |
249 </pre></div> | |
250 </div> | |
251 </p> | |
252 </p> | |
253 </dd></dl> | |
254 | |
255 <dl class="cpp function"> | |
256 <dt id="_CPPv4N3fmt6vprintE11string_view11format_args"> | |
257 <span id="_CPPv3N3fmt6vprintE11string_view11format_args"></span><span id="_CPPv2N3fmt6vprintE11string_view11format_args"></span><span id="fmt::vprint__string_view.format_args"></span><span class="target" id="core_8h_1a09c43e4ca3fd68c12d08b3de59229400"></span>void <code class="sig-prename descclassname"><a class="reference internal" href="#_CPPv4N3fmt6vprintE11string_view11format_args" title="fmt::vprint::fmt">fmt</a><code class="sig-prename descclassname">::</code></code><code class="sig-name descname">vprint</code><span class="sig-paren">(</span><a class="reference internal" href="#_CPPv4N3fmt11string_viewE" title="fmt::string_view">string_view</a> <em>fmt</em>, <a class="reference internal" href="#_CPPv4N3fmt11format_argsE" title="fmt::format_args">format_args</a> <em>args</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4N3fmt6vprintE11string_view11format_args" title="Permalink to this definition">¶</a><br /></dt> | |
258 <dd></dd></dl> | |
259 | |
260 <dl class="cpp function"> | |
261 <dt id="_CPPv4IDpEN3fmt5printEvPNSt4FILEE13format_stringIDp1TEDpRR1T"> | |
262 <span id="_CPPv3IDpEN3fmt5printEPNSt4FILEE13format_stringIDp1TEDpRR1T"></span><span id="_CPPv2IDpEN3fmt5printEPNSt4FILEE13format_stringIDp1TEDpRR1T"></span>template<typename ...<code class="sig-name descname">T</code>><br /><span class="target" id="core_8h_1a92c3da68a9590d3233b95ffa1f91fa7b"></span>void <code class="sig-prename descclassname"><a class="reference internal" href="#_CPPv4IDpEN3fmt5printEvPNSt4FILEE13format_stringIDp1TEDpRR1T" title="fmt::print::fmt">fmt</a><code class="sig-prename descclassname">::</code></code><code class="sig-name descname">print</code><span class="sig-paren">(</span>std::FILE *<em>f</em>, <a class="reference internal" href="#_CPPv4IDpEN3fmt13format_stringE" title="fmt::format_string">format_string</a><<a class="reference internal" href="#_CPPv4IDpEN3fmt5printEvPNSt4FILEE13format_stringIDp1TEDpRR1T" title="fmt::print::T">T</a>...> <em>fmt</em>, <a class="reference internal" href="#_CPPv4IDpEN3fmt5printEvPNSt4FILEE13format_stringIDp1TEDpRR1T" title="fmt::print::T">T</a>&&... <em>args</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4IDpEN3fmt5printEvPNSt4FILEE13format_stringIDp1TEDpRR1T" title="Permalink to this definition">¶</a><br /></dt> | |
263 <dd><p><p><p>Formats <code class="docutils literal notranslate"><span class="pre">args</span></code> according to specifications in <code class="docutils literal notranslate"><span class="pre">fmt</span></code> and writes the | |
264 output to the file <code class="docutils literal notranslate"><span class="pre">f</span></code>.</p> | |
265 <p><strong>Example</strong>:</p> | |
266 <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">"Don't {}!"</span><span class="p">,</span><span class="w"> </span><span class="s">"panic"</span><span class="p">);</span> | |
267 </pre></div> | |
268 </div> | |
269 </p> | |
270 </p> | |
271 </dd></dl> | |
272 | |
273 <dl class="cpp function"> | |
274 <dt id="_CPPv4N3fmt6vprintEPNSt4FILEE11string_view11format_args"> | |
275 <span id="_CPPv3N3fmt6vprintEPNSt4FILEE11string_view11format_args"></span><span id="_CPPv2N3fmt6vprintEPNSt4FILEE11string_view11format_args"></span><span id="fmt::vprint__std::FILEP.string_view.format_args"></span><span class="target" id="core_8h_1a59d85226f0b53348b3c8b9a1c88a6daa"></span>void <code class="sig-prename descclassname"><a class="reference internal" href="#_CPPv4N3fmt6vprintEPNSt4FILEE11string_view11format_args" title="fmt::vprint::fmt">fmt</a><code class="sig-prename descclassname">::</code></code><code class="sig-name descname">vprint</code><span class="sig-paren">(</span>std::FILE *<em>f</em>, <a class="reference internal" href="#_CPPv4N3fmt11string_viewE" title="fmt::string_view">string_view</a> <em>fmt</em>, <a class="reference internal" href="#_CPPv4N3fmt11format_argsE" title="fmt::format_args">format_args</a> <em>args</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4N3fmt6vprintEPNSt4FILEE11string_view11format_args" title="Permalink to this definition">¶</a><br /></dt> | |
276 <dd></dd></dl> | |
277 | |
278 <section id="compile-time-format-string-checks"> | |
279 <h3>Compile-Time Format String Checks<a class="headerlink" href="#compile-time-format-string-checks" title="Permalink to this headline">¶</a></h3> | |
280 <p>Compile-time format string checks are enabled by default on compilers | |
281 that support C++20 <code class="docutils literal notranslate"><span class="pre">consteval</span></code>. On older compilers you can use the | |
282 <a class="reference internal" href="#legacy-checks"><span class="std std-ref">FMT_STRING</span></a>: macro defined in <code class="docutils literal notranslate"><span class="pre">fmt/format.h</span></code> instead.</p> | |
283 <p>Unused arguments are allowed as in Python’s <code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">str.format</span></code> and ordinary functions.</p> | |
284 <dl class="cpp class"> | |
285 <dt id="_CPPv4I0DpEN3fmt19basic_format_stringE"> | |
286 <span id="_CPPv3I0DpEN3fmt19basic_format_stringE"></span><span id="_CPPv2I0DpEN3fmt19basic_format_stringE"></span>template<typename <code class="sig-name descname">Char</code>, typename ...<code class="sig-name descname">Args</code>><br /><span class="target" id="classfmt_1_1basic__format__string"></span><em class="property">class </em><code class="sig-name descname">basic_format_string</code><a class="headerlink" href="#_CPPv4I0DpEN3fmt19basic_format_stringE" title="Permalink to this definition">¶</a><br /></dt> | |
287 <dd><p>A compile-time format string. </p> | |
288 </dd></dl> | |
289 | |
290 <dl class="cpp type"> | |
291 <dt id="_CPPv4IDpEN3fmt13format_stringE"> | |
292 <span id="_CPPv3IDpEN3fmt13format_stringE"></span><span id="_CPPv2IDpEN3fmt13format_stringE"></span>template<typename ...<code class="sig-name descname">Args</code>><br /><span class="target" id="core_8h_1a6151137b384766b8e3d283bcdbb05145"></span><em class="property">using </em><code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">format_string</code> = <a class="reference internal" href="#_CPPv4I0DpEN3fmt19basic_format_stringE" title="fmt::basic_format_string">basic_format_string</a><char, type_identity_t<<a class="reference internal" href="#_CPPv4IDpEN3fmt13format_stringE" title="fmt::format_string::Args">Args</a>>...><a class="headerlink" href="#_CPPv4IDpEN3fmt13format_stringE" title="Permalink to this definition">¶</a><br /></dt> | |
293 <dd></dd></dl> | |
294 | |
295 <dl class="cpp function"> | |
296 <dt id="_CPPv4N3fmt7runtimeE11string_view"> | |
297 <span id="_CPPv3N3fmt7runtimeE11string_view"></span><span id="_CPPv2N3fmt7runtimeE11string_view"></span><span id="fmt::runtime__string_view"></span><span class="target" id="core_8h_1a5ebe213f4d505408abcfe01f5fa24c3b"></span>auto <code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">runtime</code><span class="sig-paren">(</span><a class="reference internal" href="#_CPPv4N3fmt11string_viewE" title="fmt::string_view">string_view</a> <em>s</em><span class="sig-paren">)</span> -> runtime_format_string<><a class="headerlink" href="#_CPPv4N3fmt7runtimeE11string_view" title="Permalink to this definition">¶</a><br /></dt> | |
298 <dd><p><p><p>Creates a runtime format string.</p> | |
299 <p><strong>Example</strong>:</p> | |
300 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="c1">// Check format string at runtime instead of compile-time.</span> | |
301 <span class="n">fmt</span><span class="o">::</span><span class="n">print</span><span class="p">(</span><span class="n">fmt</span><span class="o">::</span><span class="n">runtime</span><span class="p">(</span><span class="s">"{:d}"</span><span class="p">),</span><span class="w"> </span><span class="s">"I am not a number"</span><span class="p">);</span> | |
302 </pre></div> | |
303 </div> | |
304 </p> | |
305 </p> | |
306 </dd></dl> | |
307 | |
308 </section> | |
309 <section id="formatting-user-defined-types"> | |
310 <span id="udt"></span><h3>Formatting User-Defined Types<a class="headerlink" href="#formatting-user-defined-types" title="Permalink to this headline">¶</a></h3> | |
311 <p>The {fmt} library provides formatters for many standard C++ types. | |
312 See <a class="reference internal" href="#ranges-api"><span class="std std-ref">fmt/ranges.h</span></a> for ranges and tuples including standard | |
313 containers such as <code class="docutils literal notranslate"><span class="pre">std::vector</span></code>, <a class="reference internal" href="#chrono-api"><span class="std std-ref">fmt/chrono.h</span></a> for date | |
314 and time formatting and <a class="reference internal" href="#std-api"><span class="std std-ref">fmt/std.h</span></a> for other standard library | |
315 types.</p> | |
316 <p>There are two ways to make a user-defined type formattable: providing a | |
317 <code class="docutils literal notranslate"><span class="pre">format_as</span></code> function or specializing the <code class="docutils literal notranslate"><span class="pre">formatter</span></code> struct template.</p> | |
318 <p>Use <code class="docutils literal notranslate"><span class="pre">format_as</span></code> if you want to make your type formattable as some other type | |
319 with the same format specifiers. The <code class="docutils literal notranslate"><span class="pre">format_as</span></code> function should take an | |
320 object of your type and return an object of a formattable type. It should be | |
321 defined in the same namespace as your type.</p> | |
322 <p>Example (<a class="reference external" href="https://godbolt.org/z/nvME4arz8">https://godbolt.org/z/nvME4arz8</a>):</p> | |
323 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf"><fmt/format.h></span> | |
324 | |
325 <span class="k">namespace</span><span class="w"> </span><span class="nn">kevin_namespacy</span><span class="w"> </span><span class="p">{</span> | |
326 <span class="k">enum</span><span class="w"> </span><span class="k">class</span><span class="w"> </span><span class="nc">film</span><span class="w"> </span><span class="p">{</span> | |
327 <span class="w"> </span><span class="n">house_of_cards</span><span class="p">,</span><span class="w"> </span><span class="n">american_beauty</span><span class="p">,</span><span class="w"> </span><span class="n">se7en</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">7</span> | |
328 <span class="p">};</span> | |
329 <span class="k">auto</span><span class="w"> </span><span class="n">format_as</span><span class="p">(</span><span class="n">film</span><span class="w"> </span><span class="n">f</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">underlying</span><span class="p">(</span><span class="n">f</span><span class="p">);</span><span class="w"> </span><span class="p">}</span> | |
330 <span class="p">}</span> | |
331 | |
332 <span class="kt">int</span><span class="w"> </span><span class="n">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span> | |
333 <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">"{}</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="w"> </span><span class="n">kevin_namespacy</span><span class="o">::</span><span class="n">film</span><span class="o">::</span><span class="n">se7en</span><span class="p">);</span><span class="w"> </span><span class="c1">// prints "7"</span> | |
334 <span class="p">}</span> | |
335 </pre></div> | |
336 </div> | |
337 <p>Using specialization is more complex but gives you full control over parsing and | |
338 formatting. To use this method specialize the <code class="docutils literal notranslate"><span class="pre">formatter</span></code> struct template for | |
339 your type and implement <code class="docutils literal notranslate"><span class="pre">parse</span></code> and <code class="docutils literal notranslate"><span class="pre">format</span></code> methods.</p> | |
340 <p>The recommended way of defining a formatter is by reusing an existing one via | |
341 inheritance or composition. This way you can support standard format specifiers | |
342 without implementing them yourself. For example:</p> | |
343 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="c1">// color.h:</span> | |
344 <span class="cp">#include</span><span class="w"> </span><span class="cpf"><fmt/core.h></span> | |
345 | |
346 <span class="k">enum</span><span class="w"> </span><span class="k">class</span><span class="w"> </span><span class="nc">color</span><span class="w"> </span><span class="p">{</span><span class="n">red</span><span class="p">,</span><span class="w"> </span><span class="n">green</span><span class="p">,</span><span class="w"> </span><span class="n">blue</span><span class="p">};</span> | |
347 | |
348 <span class="k">template</span><span class="w"> </span><span class="o"><></span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">fmt</span><span class="o">::</span><span class="n">formatter</span><span class="o"><</span><span class="n">color</span><span class="o">>:</span><span class="w"> </span><span class="n">formatter</span><span class="o"><</span><span class="n">string_view</span><span class="o">></span><span class="w"> </span><span class="p">{</span> | |
349 <span class="w"> </span><span class="c1">// parse is inherited from formatter<string_view>.</span> | |
350 | |
351 <span class="w"> </span><span class="k">auto</span><span class="w"> </span><span class="n">format</span><span class="p">(</span><span class="n">color</span><span class="w"> </span><span class="n">c</span><span class="p">,</span><span class="w"> </span><span class="n">format_context</span><span class="o">&</span><span class="w"> </span><span class="n">ctx</span><span class="p">)</span><span class="w"> </span><span class="k">const</span><span class="p">;</span> | |
352 <span class="p">};</span> | |
353 | |
354 <span class="c1">// color.cc:</span> | |
355 <span class="cp">#include</span><span class="w"> </span><span class="cpf">"color.h"</span> | |
356 <span class="cp">#include</span><span class="w"> </span><span class="cpf"><fmt/format.h></span> | |
357 | |
358 <span class="k">auto</span><span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">formatter</span><span class="o"><</span><span class="n">color</span><span class="o">>::</span><span class="n">format</span><span class="p">(</span><span class="n">color</span><span class="w"> </span><span class="n">c</span><span class="p">,</span><span class="w"> </span><span class="n">format_context</span><span class="o">&</span><span class="w"> </span><span class="n">ctx</span><span class="p">)</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="p">{</span> | |
359 <span class="w"> </span><span class="n">string_view</span><span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"unknown"</span><span class="p">;</span> | |
360 <span class="w"> </span><span class="k">switch</span><span class="w"> </span><span class="p">(</span><span class="n">c</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> | |
361 <span class="w"> </span><span class="k">case</span><span class="w"> </span><span class="no">color</span><span class="o">::</span><span class="no">red</span><span class="p">:</span><span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"red"</span><span class="p">;</span><span class="w"> </span><span class="k">break</span><span class="p">;</span> | |
362 <span class="w"> </span><span class="k">case</span><span class="w"> </span><span class="no">color</span><span class="o">::</span><span class="no">green</span><span class="p">:</span><span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"green"</span><span class="p">;</span><span class="w"> </span><span class="k">break</span><span class="p">;</span> | |
363 <span class="w"> </span><span class="k">case</span><span class="w"> </span><span class="no">color</span><span class="o">::</span><span class="no">blue</span><span class="p">:</span><span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"blue"</span><span class="p">;</span><span class="w"> </span><span class="k">break</span><span class="p">;</span> | |
364 <span class="w"> </span><span class="p">}</span> | |
365 <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">formatter</span><span class="o"><</span><span class="n">string_view</span><span class="o">>::</span><span class="n">format</span><span class="p">(</span><span class="n">name</span><span class="p">,</span><span class="w"> </span><span class="n">ctx</span><span class="p">);</span> | |
366 <span class="p">}</span> | |
367 </pre></div> | |
368 </div> | |
369 <p>Note that <code class="docutils literal notranslate"><span class="pre">formatter<string_view>::format</span></code> is defined in <code class="docutils literal notranslate"><span class="pre">fmt/format.h</span></code> so | |
370 it has to be included in the source file. Since <code class="docutils literal notranslate"><span class="pre">parse</span></code> is inherited from | |
371 <code class="docutils literal notranslate"><span class="pre">formatter<string_view></span></code> it will recognize all string format specifications, | |
372 for example</p> | |
373 <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">"{:>10}"</span><span class="p">,</span><span class="w"> </span><span class="n">color</span><span class="o">::</span><span class="n">blue</span><span class="p">)</span> | |
374 </pre></div> | |
375 </div> | |
376 <p>will return <code class="docutils literal notranslate"><span class="pre">"</span>      <span class="pre">blue"</span></code>.</p> | |
377 <p>The experimental <code class="docutils literal notranslate"><span class="pre">nested_formatter</span></code> provides an easy way of applying a | |
378 formatter to one or more subobjects.</p> | |
379 <p>For example:</p> | |
380 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf"><fmt/format.h></span> | |
381 | |
382 <span class="k">struct</span><span class="w"> </span><span class="nc">point</span><span class="w"> </span><span class="p">{</span> | |
383 <span class="w"> </span><span class="kt">double</span><span class="w"> </span><span class="n">x</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="p">;</span> | |
384 <span class="p">};</span> | |
385 | |
386 <span class="k">template</span><span class="w"> </span><span class="o"><></span> | |
387 <span class="k">struct</span><span class="w"> </span><span class="nc">fmt</span><span class="o">::</span><span class="n">formatter</span><span class="o"><</span><span class="n">point</span><span class="o">></span><span class="w"> </span><span class="o">:</span><span class="w"> </span><span class="n">nested_formatter</span><span class="o"><</span><span class="kt">double</span><span class="o">></span><span class="w"> </span><span class="p">{</span> | |
388 <span class="w"> </span><span class="k">auto</span><span class="w"> </span><span class="n">format</span><span class="p">(</span><span class="n">point</span><span class="w"> </span><span class="n">p</span><span class="p">,</span><span class="w"> </span><span class="n">format_context</span><span class="o">&</span><span class="w"> </span><span class="n">ctx</span><span class="p">)</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="p">{</span> | |
389 <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">write_padded</span><span class="p">(</span><span class="n">ctx</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="o">=</span><span class="p">](</span><span class="k">auto</span><span class="w"> </span><span class="n">out</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> | |
390 <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">format_to</span><span class="p">(</span><span class="n">out</span><span class="p">,</span><span class="w"> </span><span class="s">"({}, {})"</span><span class="p">,</span><span class="w"> </span><span class="n">nested</span><span class="p">(</span><span class="n">p</span><span class="p">.</span><span class="n">x</span><span class="p">),</span><span class="w"> </span><span class="n">nested</span><span class="p">(</span><span class="n">p</span><span class="p">.</span><span class="n">y</span><span class="p">));</span> | |
391 <span class="w"> </span><span class="p">});</span> | |
392 <span class="w"> </span><span class="p">}</span> | |
393 <span class="p">};</span> | |
394 | |
395 <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> | |
396 <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">"[{:>20.2f}]"</span><span class="p">,</span><span class="w"> </span><span class="n">point</span><span class="p">{</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">});</span> | |
397 <span class="p">}</span> | |
398 </pre></div> | |
399 </div> | |
400 <p>prints:</p> | |
401 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="p">[</span><span class="w"> </span><span class="p">(</span><span class="mf">1.00</span><span class="p">,</span><span class="w"> </span><span class="mf">2.00</span><span class="p">)]</span> | |
402 </pre></div> | |
403 </div> | |
404 <p>Notice that fill, align and width are applied to the whole object which is the | |
405 recommended behavior while the remaining specifiers apply to elements.</p> | |
406 <p>In general the formatter has the following form:</p> | |
407 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="k">template</span><span class="w"> </span><span class="o"><></span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">fmt</span><span class="o">::</span><span class="n">formatter</span><span class="o"><</span><span class="n">T</span><span class="o">></span><span class="w"> </span><span class="p">{</span> | |
408 <span class="w"> </span><span class="c1">// Parses format specifiers and stores them in the formatter.</span> | |
409 <span class="w"> </span><span class="c1">//</span> | |
410 <span class="w"> </span><span class="c1">// [ctx.begin(), ctx.end()) is a, possibly empty, character range that</span> | |
411 <span class="w"> </span><span class="c1">// contains a part of the format string starting from the format</span> | |
412 <span class="w"> </span><span class="c1">// specifications to be parsed, e.g. in</span> | |
413 <span class="w"> </span><span class="c1">//</span> | |
414 <span class="w"> </span><span class="c1">// fmt::format("{:f} continued", ...);</span> | |
415 <span class="w"> </span><span class="c1">//</span> | |
416 <span class="w"> </span><span class="c1">// the range will contain "f} continued". The formatter should parse</span> | |
417 <span class="w"> </span><span class="c1">// specifiers until '}' or the end of the range. In this example the</span> | |
418 <span class="w"> </span><span class="c1">// formatter should parse the 'f' specifier and return an iterator</span> | |
419 <span class="w"> </span><span class="c1">// pointing to '}'.</span> | |
420 <span class="w"> </span><span class="k">constexpr</span><span class="w"> </span><span class="k">auto</span><span class="w"> </span><span class="n">parse</span><span class="p">(</span><span class="n">format_parse_context</span><span class="o">&</span><span class="w"> </span><span class="n">ctx</span><span class="p">)</span> | |
421 <span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="n">format_parse_context</span><span class="o">::</span><span class="n">iterator</span><span class="p">;</span> | |
422 | |
423 <span class="w"> </span><span class="c1">// Formats value using the parsed format specification stored in this</span> | |
424 <span class="w"> </span><span class="c1">// formatter and writes the output to ctx.out().</span> | |
425 <span class="w"> </span><span class="k">auto</span><span class="w"> </span><span class="n">format</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="n">T</span><span class="o">&</span><span class="w"> </span><span class="n">value</span><span class="p">,</span><span class="w"> </span><span class="n">format_context</span><span class="o">&</span><span class="w"> </span><span class="n">ctx</span><span class="p">)</span><span class="w"> </span><span class="k">const</span> | |
426 <span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="n">format_context</span><span class="o">::</span><span class="n">iterator</span><span class="p">;</span> | |
427 <span class="p">};</span> | |
428 </pre></div> | |
429 </div> | |
430 <p>It is recommended to at least support fill, align and width that apply to the | |
431 whole object and have the same semantics as in standard formatters.</p> | |
432 <p>You can also write a formatter for a hierarchy of classes:</p> | |
433 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="c1">// demo.h:</span> | |
434 <span class="cp">#include</span><span class="w"> </span><span class="cpf"><type_traits></span> | |
435 <span class="cp">#include</span><span class="w"> </span><span class="cpf"><fmt/core.h></span> | |
436 | |
437 <span class="k">struct</span><span class="w"> </span><span class="nc">A</span><span class="w"> </span><span class="p">{</span> | |
438 <span class="w"> </span><span class="k">virtual</span><span class="w"> </span><span class="o">~</span><span class="n">A</span><span class="p">()</span><span class="w"> </span><span class="p">{}</span> | |
439 <span class="w"> </span><span class="k">virtual</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="w"> </span><span class="n">name</span><span class="p">()</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="s">"A"</span><span class="p">;</span><span class="w"> </span><span class="p">}</span> | |
440 <span class="p">};</span> | |
441 | |
442 <span class="k">struct</span><span class="w"> </span><span class="nc">B</span><span class="w"> </span><span class="o">:</span><span class="w"> </span><span class="n">A</span><span class="w"> </span><span class="p">{</span> | |
443 <span class="w"> </span><span class="k">virtual</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="w"> </span><span class="nf">name</span><span class="p">()</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="s">"B"</span><span class="p">;</span><span class="w"> </span><span class="p">}</span> | |
444 <span class="p">};</span> | |
445 | |
446 <span class="k">template</span><span class="w"> </span><span class="o"><</span><span class="k">typename</span><span class="w"> </span><span class="nc">T</span><span class="o">></span> | |
447 <span class="k">struct</span><span class="w"> </span><span class="nc">fmt</span><span class="o">::</span><span class="n">formatter</span><span class="o"><</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">enable_if_t</span><span class="o"><</span><span class="n">std</span><span class="o">::</span><span class="n">is_base_of</span><span class="o"><</span><span class="n">A</span><span class="p">,</span><span class="w"> </span><span class="n">T</span><span class="o">>::</span><span class="n">value</span><span class="p">,</span><span class="w"> </span><span class="kt">char</span><span class="o">>></span><span class="w"> </span><span class="o">:</span> | |
448 <span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">formatter</span><span class="o"><</span><span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">></span><span class="w"> </span><span class="p">{</span> | |
449 <span class="w"> </span><span class="k">auto</span><span class="w"> </span><span class="n">format</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="n">A</span><span class="o">&</span><span class="w"> </span><span class="n">a</span><span class="p">,</span><span class="w"> </span><span class="n">format_context</span><span class="o">&</span><span class="w"> </span><span class="n">ctx</span><span class="p">)</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="p">{</span> | |
450 <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">formatter</span><span class="o"><</span><span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">>::</span><span class="n">format</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">name</span><span class="p">(),</span><span class="w"> </span><span class="n">ctx</span><span class="p">);</span> | |
451 <span class="w"> </span><span class="p">}</span> | |
452 <span class="p">};</span> | |
453 | |
454 <span class="c1">// demo.cc:</span> | |
455 <span class="cp">#include</span><span class="w"> </span><span class="cpf">"demo.h"</span> | |
456 <span class="cp">#include</span><span class="w"> </span><span class="cpf"><fmt/format.h></span> | |
457 | |
458 <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> | |
459 <span class="w"> </span><span class="n">B</span><span class="w"> </span><span class="n">b</span><span class="p">;</span> | |
460 <span class="w"> </span><span class="n">A</span><span class="o">&</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">b</span><span class="p">;</span> | |
461 <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">"{}"</span><span class="p">,</span><span class="w"> </span><span class="n">a</span><span class="p">);</span><span class="w"> </span><span class="c1">// prints "B"</span> | |
462 <span class="p">}</span> | |
463 </pre></div> | |
464 </div> | |
465 <p>Providing both a <code class="docutils literal notranslate"><span class="pre">formatter</span></code> specialization and a <code class="docutils literal notranslate"><span class="pre">format_as</span></code> overload is | |
466 disallowed.</p> | |
467 </section> | |
468 <section id="named-arguments"> | |
469 <h3>Named Arguments<a class="headerlink" href="#named-arguments" title="Permalink to this headline">¶</a></h3> | |
470 <dl class="cpp function"> | |
471 <dt id="_CPPv4I00EN3fmt3argEN6detail9named_argI4Char1TEEPK4CharRK1T"> | |
472 <span id="_CPPv3I00EN3fmt3argEPK4CharRK1T"></span><span id="_CPPv2I00EN3fmt3argEPK4CharRK1T"></span>template<typename <code class="sig-name descname">Char</code>, typename <code class="sig-name descname">T</code>><br /><span class="target" id="core_8h_1a0186a488c80ab72f718b8d001960b1e9"></span>auto <code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">arg</code><span class="sig-paren">(</span><em class="property">const</em> <a class="reference internal" href="#_CPPv4I00EN3fmt3argEN6detail9named_argI4Char1TEEPK4CharRK1T" title="fmt::arg::Char">Char</a> *<em>name</em>, <em class="property">const</em> <a class="reference internal" href="#_CPPv4I00EN3fmt3argEN6detail9named_argI4Char1TEEPK4CharRK1T" title="fmt::arg::T">T</a> &<em>arg</em><span class="sig-paren">)</span> -> detail::named_arg<<a class="reference internal" href="#_CPPv4I00EN3fmt3argEN6detail9named_argI4Char1TEEPK4CharRK1T" title="fmt::arg::Char">Char</a>, <a class="reference internal" href="#_CPPv4I00EN3fmt3argEN6detail9named_argI4Char1TEEPK4CharRK1T" title="fmt::arg::T">T</a>><a class="headerlink" href="#_CPPv4I00EN3fmt3argEN6detail9named_argI4Char1TEEPK4CharRK1T" title="Permalink to this definition">¶</a><br /></dt> | |
473 <dd><p><p><p>Returns a named argument to be used in a formatting function. | |
474 It should only be used in a call to a formatting function or | |
475 <a class="reference internal" href="#_CPPv4I0EN3fmt24dynamic_format_arg_store9push_backEvRK1T" title="fmt::dynamic_format_arg_store::push_back"><code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">dynamic_format_arg_store::push_back()</span></code></a>.</p> | |
476 <p><strong>Example</strong>:</p> | |
477 <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">"Elapsed time: {s:.2f} seconds"</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">"s"</span><span class="p">,</span><span class="w"> </span><span class="mf">1.23</span><span class="p">));</span> | |
478 </pre></div> | |
479 </div> | |
480 </p> | |
481 </p> | |
482 </dd></dl> | |
483 | |
484 <p>Named arguments are not supported in compile-time checks at the moment.</p> | |
485 </section> | |
486 <section id="argument-lists"> | |
487 <h3>Argument Lists<a class="headerlink" href="#argument-lists" title="Permalink to this headline">¶</a></h3> | |
488 <p>You can create your own formatting function with compile-time checks and small | |
489 binary footprint, for example (<a class="reference external" href="https://godbolt.org/z/vajfWEG4b">https://godbolt.org/z/vajfWEG4b</a>):</p> | |
490 <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> | |
491 | |
492 <span class="kt">void</span><span class="w"> </span><span class="nf">vlog</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="kt">char</span><span class="o">*</span><span class="w"> </span><span class="n">file</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">line</span><span class="p">,</span><span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">string_view</span><span class="w"> </span><span class="n">format</span><span class="p">,</span> | |
493 <span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">format_args</span><span class="w"> </span><span class="n">args</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> | |
494 <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">"{}: {}: "</span><span class="p">,</span><span class="w"> </span><span class="n">file</span><span class="p">,</span><span class="w"> </span><span class="n">line</span><span class="p">);</span> | |
495 <span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">vprint</span><span class="p">(</span><span class="n">format</span><span class="p">,</span><span class="w"> </span><span class="n">args</span><span class="p">);</span> | |
496 <span class="p">}</span> | |
497 | |
498 <span class="k">template</span><span class="w"> </span><span class="o"><</span><span class="k">typename</span><span class="p">...</span><span class="w"> </span><span class="n">T</span><span class="o">></span> | |
499 <span class="kt">void</span><span class="w"> </span><span class="n">log</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="kt">char</span><span class="o">*</span><span class="w"> </span><span class="n">file</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">line</span><span class="p">,</span><span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">format_string</span><span class="o"><</span><span class="n">T</span><span class="p">...</span><span class="o">></span><span class="w"> </span><span class="n">format</span><span class="p">,</span><span class="w"> </span><span class="n">T</span><span class="o">&&</span><span class="p">...</span><span class="w"> </span><span class="n">args</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> | |
500 <span class="w"> </span><span class="n">vlog</span><span class="p">(</span><span class="n">file</span><span class="p">,</span><span class="w"> </span><span class="n">line</span><span class="p">,</span><span class="w"> </span><span class="n">format</span><span class="p">,</span><span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">make_format_args</span><span class="p">(</span><span class="n">args</span><span class="p">...));</span> | |
501 <span class="p">}</span> | |
502 | |
503 <span class="cp">#define MY_LOG(format, ...) log(__FILE__, __LINE__, format, __VA_ARGS__)</span> | |
504 | |
505 <span class="n">MY_LOG</span><span class="p">(</span><span class="s">"invalid squishiness: {}"</span><span class="p">,</span><span class="w"> </span><span class="mi">42</span><span class="p">);</span> | |
506 </pre></div> | |
507 </div> | |
508 <p>Note that <code class="docutils literal notranslate"><span class="pre">vlog</span></code> is not parameterized on argument types which improves compile | |
509 times and reduces binary code size compared to a fully parameterized version.</p> | |
510 <dl class="cpp function"> | |
511 <dt id="_CPPv4I0DpEN3fmt16make_format_argsE16format_arg_storeI7ContextDp14remove_cvref_tI1TEEDpR1T"> | |
512 <span id="_CPPv3I0DpEN3fmt16make_format_argsEDpR1T"></span><span id="_CPPv2I0DpEN3fmt16make_format_argsEDpR1T"></span>template<typename <code class="sig-name descname">Context</code> = <a class="reference internal" href="#_CPPv4N3fmt14format_contextE" title="fmt::format_context">format_context</a>, typename ...<code class="sig-name descname">T</code>><br /><span class="target" id="core_8h_1ae17debf20cdb02049729e0db732ea89a"></span><em class="property">constexpr</em> auto <code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">make_format_args</code><span class="sig-paren">(</span><a class="reference internal" href="#_CPPv4I0DpEN3fmt16make_format_argsE16format_arg_storeI7ContextDp14remove_cvref_tI1TEEDpR1T" title="fmt::make_format_args::T">T</a>&... <em>args</em><span class="sig-paren">)</span> -> <a class="reference internal" href="#_CPPv4I0DpEN3fmt16format_arg_storeE" title="fmt::format_arg_store">format_arg_store</a><<a class="reference internal" href="#_CPPv4I0DpEN3fmt16make_format_argsE16format_arg_storeI7ContextDp14remove_cvref_tI1TEEDpR1T" title="fmt::make_format_args::Context">Context</a>, remove_cvref_t<<a class="reference internal" href="#_CPPv4I0DpEN3fmt16make_format_argsE16format_arg_storeI7ContextDp14remove_cvref_tI1TEEDpR1T" title="fmt::make_format_args::T">T</a>>...><a class="headerlink" href="#_CPPv4I0DpEN3fmt16make_format_argsE16format_arg_storeI7ContextDp14remove_cvref_tI1TEEDpR1T" title="Permalink to this definition">¶</a><br /></dt> | |
513 <dd><p><p><p>Constructs a <a class="reference internal" href="#_CPPv4I0DpEN3fmt16format_arg_storeE" title="fmt::format_arg_store"><code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">format_arg_store</span></code></a> object that contains references to | |
514 arguments and can be implicitly converted to <a class="reference internal" href="#_CPPv4N3fmt11format_argsE" title="fmt::format_args"><code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">format_args</span></code></a>. <a class="reference internal" href="#_CPPv4I0DpEN3fmt16make_format_argsE16format_arg_storeI7ContextDp14remove_cvref_tI1TEEDpR1T" title="fmt::make_format_args::Context"><code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">Context</span></code></a> | |
515 can be omitted in which case it defaults to <a class="reference internal" href="#_CPPv4N3fmt14format_contextE" title="fmt::format_context"><code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">format_context</span></code></a>. | |
516 See <a class="reference internal" href="#_CPPv4I00EN3fmt3argEN6detail9named_argI4Char1TEEPK4CharRK1T" title="fmt::arg"><code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">arg()</span></code></a> for lifetime considerations.</p> | |
517 </p> | |
518 </p> | |
519 </dd></dl> | |
520 | |
521 <dl class="cpp class"> | |
522 <dt id="_CPPv4I0DpEN3fmt16format_arg_storeE"> | |
523 <span id="_CPPv3I0DpEN3fmt16format_arg_storeE"></span><span id="_CPPv2I0DpEN3fmt16format_arg_storeE"></span>template<typename <code class="sig-name descname">Context</code>, typename ...<code class="sig-name descname">Args</code>><br /><span class="target" id="classfmt_1_1format__arg__store"></span><em class="property">class </em><code class="sig-name descname">format_arg_store</code><a class="headerlink" href="#_CPPv4I0DpEN3fmt16format_arg_storeE" title="Permalink to this definition">¶</a><br /></dt> | |
524 <dd><p><p><p>An array of references to arguments. It can be implicitly converted into | |
525 <a class="reference internal" href="#_CPPv4I0EN3fmt17basic_format_argsE" title="fmt::basic_format_args"><code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">basic_format_args</span></code></a> for passing into type-erased formatting functions | |
526 such as <a class="reference internal" href="#_CPPv4N3fmt7vformatE11string_view11format_args" title="fmt::vformat"><code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">vformat()</span></code></a>.</p> | |
527 </p> | |
528 </p> | |
529 </dd></dl> | |
530 | |
531 <dl class="cpp class"> | |
532 <dt id="_CPPv4I0EN3fmt17basic_format_argsE"> | |
533 <span id="_CPPv3I0EN3fmt17basic_format_argsE"></span><span id="_CPPv2I0EN3fmt17basic_format_argsE"></span>template<typename <code class="sig-name descname">Context</code>><br /><span class="target" id="classfmt_1_1basic__format__args"></span><em class="property">class </em><code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">basic_format_args</code><a class="headerlink" href="#_CPPv4I0EN3fmt17basic_format_argsE" title="Permalink to this definition">¶</a><br /></dt> | |
534 <dd><p><p><p>A view of a collection of formatting arguments. To avoid lifetime issues it | |
535 should only be used as a parameter type in type-erased functions such as | |
536 <code class="docutils literal notranslate"><span class="pre">vformat</span></code>:</p> | |
537 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="kt">void</span><span class="w"> </span><span class="nf">vlog</span><span class="p">(</span><span class="n">string_view</span><span class="w"> </span><span class="n">format_str</span><span class="p">,</span><span class="w"> </span><span class="n">format_args</span><span class="w"> </span><span class="n">args</span><span class="p">);</span><span class="w"> </span><span class="c1">// OK</span> | |
538 <span class="n">format_args</span><span class="w"> </span><span class="n">args</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">make_format_args</span><span class="p">();</span><span class="w"> </span><span class="c1">// Error: dangling reference</span> | |
539 </pre></div> | |
540 </div> | |
541 </p> | |
542 </p> | |
543 <div class="breathe-sectiondef docutils container"> | |
544 <p class="breathe-sectiondef-title rubric">Public Functions</p> | |
545 <dl class="cpp function"> | |
546 <dt id="_CPPv4IDpEN3fmt17basic_format_args17basic_format_argsERK16format_arg_storeI7ContextDp4ArgsE"> | |
547 <span id="_CPPv3IDpEN3fmt17basic_format_args17basic_format_argsERK16format_arg_storeI7ContextDp4ArgsE"></span><span id="_CPPv2IDpEN3fmt17basic_format_args17basic_format_argsERK16format_arg_storeI7ContextDp4ArgsE"></span>template<typename ...<code class="sig-name descname">Args</code>><br /><span class="target" id="classfmt_1_1basic__format__args_1aa29b9df6b51427157eb9c4881a12cc19"></span><em class="property">constexpr</em> <code class="sig-name descname">basic_format_args</code><span class="sig-paren">(</span><em class="property">const</em> <a class="reference internal" href="#_CPPv4I0DpEN3fmt16format_arg_storeE" title="fmt::format_arg_store">format_arg_store</a><<a class="reference internal" href="#_CPPv4I0EN3fmt17basic_format_argsE" title="fmt::basic_format_args::Context">Context</a>, <a class="reference internal" href="#_CPPv4IDpEN3fmt17basic_format_args17basic_format_argsERK16format_arg_storeI7ContextDp4ArgsE" title="fmt::basic_format_args::basic_format_args::Args">Args</a>...> &<em>store</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4IDpEN3fmt17basic_format_args17basic_format_argsERK16format_arg_storeI7ContextDp4ArgsE" title="Permalink to this definition">¶</a><br /></dt> | |
548 <dd><p><p><p>Constructs a <a class="reference internal" href="#_CPPv4IDpEN3fmt17basic_format_args17basic_format_argsERK16format_arg_storeI7ContextDp4ArgsE" title="fmt::basic_format_args::basic_format_args"><code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">basic_format_args()</span></code></a> object from <a class="reference internal" href="#_CPPv4I0DpEN3fmt16format_arg_storeE" title="fmt::format_arg_store"><code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">format_arg_store</span></code></a>.</p> | |
549 </p> | |
550 </p> | |
551 </dd></dl> | |
552 | |
553 <dl class="cpp function"> | |
554 <dt id="_CPPv4N3fmt17basic_format_args17basic_format_argsERK24dynamic_format_arg_storeI7ContextE"> | |
555 <span id="_CPPv3N3fmt17basic_format_args17basic_format_argsERK24dynamic_format_arg_storeI7ContextE"></span><span id="_CPPv2N3fmt17basic_format_args17basic_format_argsERK24dynamic_format_arg_storeI7ContextE"></span><span id="fmt::basic_format_args::basic_format_args__dynamic_format_arg_store:Context:CRCE"></span><span class="target" id="classfmt_1_1basic__format__args_1a9708feb267c220363a56f82348cd3809"></span><em class="property">constexpr</em> <code class="sig-name descname">basic_format_args</code><span class="sig-paren">(</span><em class="property">const</em> <a class="reference internal" href="#_CPPv4I0EN3fmt24dynamic_format_arg_storeE" title="fmt::dynamic_format_arg_store">dynamic_format_arg_store</a><<a class="reference internal" href="#_CPPv4I0EN3fmt17basic_format_argsE" title="fmt::basic_format_args::Context">Context</a>> &<em>store</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4N3fmt17basic_format_args17basic_format_argsERK24dynamic_format_arg_storeI7ContextE" title="Permalink to this definition">¶</a><br /></dt> | |
556 <dd><p><p><p>Constructs a <a class="reference internal" href="#_CPPv4N3fmt17basic_format_args17basic_format_argsERK24dynamic_format_arg_storeI7ContextE" title="fmt::basic_format_args::basic_format_args"><code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">basic_format_args()</span></code></a> object from | |
557 <a class="reference internal" href="#_CPPv4I0EN3fmt24dynamic_format_arg_storeE" title="fmt::dynamic_format_arg_store"><code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">dynamic_format_arg_store</span></code></a>.</p> | |
558 </p> | |
559 </p> | |
560 </dd></dl> | |
561 | |
562 <dl class="cpp function"> | |
563 <dt id="_CPPv4N3fmt17basic_format_args17basic_format_argsEPK10format_argi"> | |
564 <span id="_CPPv3N3fmt17basic_format_args17basic_format_argsEPK10format_argi"></span><span id="_CPPv2N3fmt17basic_format_args17basic_format_argsEPK10format_argi"></span><span id="fmt::basic_format_args::basic_format_args__format_argCP.iCE"></span><span class="target" id="classfmt_1_1basic__format__args_1abd2d437108168771b2cbbf947c84d9c1"></span><em class="property">constexpr</em> <code class="sig-name descname">basic_format_args</code><span class="sig-paren">(</span><em class="property">const</em> format_arg *<em>args</em>, int <em>count</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4N3fmt17basic_format_args17basic_format_argsEPK10format_argi" title="Permalink to this definition">¶</a><br /></dt> | |
565 <dd><p><p><p>Constructs a <a class="reference internal" href="#_CPPv4N3fmt17basic_format_args17basic_format_argsEPK10format_argi" title="fmt::basic_format_args::basic_format_args"><code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">basic_format_args()</span></code></a> object from a dynamic set of arguments.</p> | |
566 </p> | |
567 </p> | |
568 </dd></dl> | |
569 | |
570 <dl class="cpp function"> | |
571 <dt id="_CPPv4NK3fmt17basic_format_args3getEi"> | |
572 <span id="_CPPv3NK3fmt17basic_format_args3getEi"></span><span id="_CPPv2NK3fmt17basic_format_args3getEi"></span><span id="fmt::basic_format_args::get__iC"></span><span class="target" id="classfmt_1_1basic__format__args_1a4714316d66a0c30e5bd3faf9c695b4f0"></span>auto <code class="sig-name descname">get</code><span class="sig-paren">(</span>int <em>id</em><span class="sig-paren">)</span> <em class="property">const</em> -> format_arg<a class="headerlink" href="#_CPPv4NK3fmt17basic_format_args3getEi" title="Permalink to this definition">¶</a><br /></dt> | |
573 <dd><p>Returns the argument with the specified id. </p> | |
574 </dd></dl> | |
575 | |
576 </div> | |
577 </dd></dl> | |
578 | |
579 <dl class="cpp type"> | |
580 <dt id="_CPPv4N3fmt11format_argsE"> | |
581 <span id="_CPPv3N3fmt11format_argsE"></span><span id="_CPPv2N3fmt11format_argsE"></span><span class="target" id="core_8h_1a2f47e63581cb37cd6377edce1d6cb131"></span><em class="property">using </em><code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">format_args</code> = <a class="reference internal" href="#_CPPv4I0EN3fmt17basic_format_argsE" title="fmt::basic_format_args">basic_format_args</a><<a class="reference internal" href="#_CPPv4N3fmt14format_contextE" title="fmt::format_context">format_context</a>><a class="headerlink" href="#_CPPv4N3fmt11format_argsE" title="Permalink to this definition">¶</a><br /></dt> | |
582 <dd><p>An alias to <code class="docutils literal notranslate"><span class="pre">basic_format_args<format_context></span></code>. </p> | |
583 </dd></dl> | |
584 | |
585 <dl class="cpp class"> | |
586 <dt id="_CPPv4I0EN3fmt16basic_format_argE"> | |
587 <span id="_CPPv3I0EN3fmt16basic_format_argE"></span><span id="_CPPv2I0EN3fmt16basic_format_argE"></span>template<typename <code class="sig-name descname">Context</code>><br /><span class="target" id="classfmt_1_1basic__format__arg"></span><em class="property">class </em><code class="sig-name descname">basic_format_arg</code><a class="headerlink" href="#_CPPv4I0EN3fmt16basic_format_argE" title="Permalink to this definition">¶</a><br /></dt> | |
588 <dd></dd></dl> | |
589 | |
590 <dl class="cpp class"> | |
591 <dt id="_CPPv4I0EN3fmt26basic_format_parse_contextE"> | |
592 <span id="_CPPv3I0EN3fmt26basic_format_parse_contextE"></span><span id="_CPPv2I0EN3fmt26basic_format_parse_contextE"></span>template<typename <code class="sig-name descname">Char</code>><br /><span class="target" id="classfmt_1_1basic__format__parse__context"></span><em class="property">class </em><code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">basic_format_parse_context</code><a class="headerlink" href="#_CPPv4I0EN3fmt26basic_format_parse_contextE" title="Permalink to this definition">¶</a><br /></dt> | |
593 <dd><p><p><p>Parsing context consisting of a format string range being parsed and an | |
594 argument counter for automatic indexing. | |
595 You can use the <code class="docutils literal notranslate"><span class="pre">format_parse_context</span></code> type alias for <code class="docutils literal notranslate"><span class="pre">char</span></code> instead.</p> | |
596 </p> | |
597 </p> | |
598 <p>Subclassed by fmt::detail::compile_parse_context< Char ></p> | |
599 <div class="breathe-sectiondef docutils container"> | |
600 <p class="breathe-sectiondef-title rubric">Public Functions</p> | |
601 <dl class="cpp function"> | |
602 <dt id="_CPPv4NK3fmt26basic_format_parse_context5beginEv"> | |
603 <span id="_CPPv3NK3fmt26basic_format_parse_context5beginEv"></span><span id="_CPPv2NK3fmt26basic_format_parse_context5beginEv"></span><span id="fmt::basic_format_parse_context::beginCCE"></span><span class="target" id="classfmt_1_1basic__format__parse__context_1aa830187d6c59f36a4641ca53e8aa6968"></span><em class="property">constexpr</em> auto <code class="sig-name descname">begin</code><span class="sig-paren">(</span><span class="sig-paren">)</span> <em class="property">const</em> <em class="property">noexcept</em> -> iterator<a class="headerlink" href="#_CPPv4NK3fmt26basic_format_parse_context5beginEv" title="Permalink to this definition">¶</a><br /></dt> | |
604 <dd><p>Returns an iterator to the beginning of the format string range being parsed. </p> | |
605 </dd></dl> | |
606 | |
607 <dl class="cpp function"> | |
608 <dt id="_CPPv4NK3fmt26basic_format_parse_context3endEv"> | |
609 <span id="_CPPv3NK3fmt26basic_format_parse_context3endEv"></span><span id="_CPPv2NK3fmt26basic_format_parse_context3endEv"></span><span id="fmt::basic_format_parse_context::endCCE"></span><span class="target" id="classfmt_1_1basic__format__parse__context_1aeabda8d18f88e74f251526131778d7fb"></span><em class="property">constexpr</em> auto <code class="sig-name descname">end</code><span class="sig-paren">(</span><span class="sig-paren">)</span> <em class="property">const</em> <em class="property">noexcept</em> -> iterator<a class="headerlink" href="#_CPPv4NK3fmt26basic_format_parse_context3endEv" title="Permalink to this definition">¶</a><br /></dt> | |
610 <dd><p>Returns an iterator past the end of the format string range being parsed. </p> | |
611 </dd></dl> | |
612 | |
613 <dl class="cpp function"> | |
614 <dt id="_CPPv4N3fmt26basic_format_parse_context10advance_toE8iterator"> | |
615 <span id="_CPPv3N3fmt26basic_format_parse_context10advance_toE8iterator"></span><span id="_CPPv2N3fmt26basic_format_parse_context10advance_toE8iterator"></span><span id="fmt::basic_format_parse_context::advance_to__iterator"></span><span class="target" id="classfmt_1_1basic__format__parse__context_1ae3aad50336bd6a39a5b12604e4817a48"></span>void <code class="sig-name descname">advance_to</code><span class="sig-paren">(</span>iterator <em>it</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4N3fmt26basic_format_parse_context10advance_toE8iterator" title="Permalink to this definition">¶</a><br /></dt> | |
616 <dd><p>Advances the begin iterator to <code class="docutils literal notranslate"><span class="pre">it</span></code>. </p> | |
617 </dd></dl> | |
618 | |
619 <dl class="cpp function"> | |
620 <dt id="_CPPv4N3fmt26basic_format_parse_context11next_arg_idEv"> | |
621 <span id="_CPPv3N3fmt26basic_format_parse_context11next_arg_idEv"></span><span id="_CPPv2N3fmt26basic_format_parse_context11next_arg_idEv"></span><span id="fmt::basic_format_parse_context::next_arg_id"></span><span class="target" id="classfmt_1_1basic__format__parse__context_1a5b7a4d2df94eb76fe99332ded3a8ff5e"></span>auto <code class="sig-name descname">next_arg_id</code><span class="sig-paren">(</span><span class="sig-paren">)</span> -> int<a class="headerlink" href="#_CPPv4N3fmt26basic_format_parse_context11next_arg_idEv" title="Permalink to this definition">¶</a><br /></dt> | |
622 <dd><p>Reports an error if using the manual argument indexing; otherwise returns the next argument index and switches to the automatic indexing. </p> | |
623 </dd></dl> | |
624 | |
625 <dl class="cpp function"> | |
626 <dt id="_CPPv4N3fmt26basic_format_parse_context12check_arg_idEi"> | |
627 <span id="_CPPv3N3fmt26basic_format_parse_context12check_arg_idEi"></span><span id="_CPPv2N3fmt26basic_format_parse_context12check_arg_idEi"></span><span id="fmt::basic_format_parse_context::check_arg_id__i"></span><span class="target" id="classfmt_1_1basic__format__parse__context_1a0978f2b02767da8f4b6e082c52ec631c"></span>void <code class="sig-name descname">check_arg_id</code><span class="sig-paren">(</span>int <em>id</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4N3fmt26basic_format_parse_context12check_arg_idEi" title="Permalink to this definition">¶</a><br /></dt> | |
628 <dd><p>Reports an error if using the automatic argument indexing; otherwise switches to the manual indexing. </p> | |
629 </dd></dl> | |
630 | |
631 </div> | |
632 </dd></dl> | |
633 | |
634 <dl class="cpp class"> | |
635 <dt id="_CPPv4I00EN3fmt20basic_format_contextE"> | |
636 <span id="_CPPv3I00EN3fmt20basic_format_contextE"></span><span id="_CPPv2I00EN3fmt20basic_format_contextE"></span>template<typename <code class="sig-name descname">OutputIt</code>, typename <code class="sig-name descname">Char</code>><br /><span class="target" id="classfmt_1_1basic__format__context"></span><em class="property">class </em><code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">basic_format_context</code><a class="headerlink" href="#_CPPv4I00EN3fmt20basic_format_contextE" title="Permalink to this definition">¶</a><br /></dt> | |
637 <dd><div class="breathe-sectiondef docutils container"> | |
638 <p class="breathe-sectiondef-title rubric">Public Types</p> | |
639 <dl class="cpp type"> | |
640 <dt id="_CPPv4N3fmt20basic_format_context9char_typeE"> | |
641 <span id="_CPPv3N3fmt20basic_format_context9char_typeE"></span><span id="_CPPv2N3fmt20basic_format_context9char_typeE"></span><span class="target" id="classfmt_1_1basic__format__context_1a2d6b20e51d17975188e4463cd3b681ae"></span><em class="property">using </em><code class="sig-name descname">char_type</code> = <a class="reference internal" href="#_CPPv4I00EN3fmt20basic_format_contextE" title="fmt::basic_format_context::Char">Char</a><a class="headerlink" href="#_CPPv4N3fmt20basic_format_context9char_typeE" title="Permalink to this definition">¶</a><br /></dt> | |
642 <dd><p>The character type for the output. </p> | |
643 </dd></dl> | |
644 | |
645 </div> | |
646 <div class="breathe-sectiondef docutils container"> | |
647 <p class="breathe-sectiondef-title rubric">Public Functions</p> | |
648 <dl class="cpp function"> | |
649 <dt id="_CPPv4N3fmt20basic_format_context20basic_format_contextE8OutputIt11format_argsN6detail10locale_refE"> | |
650 <span id="_CPPv3N3fmt20basic_format_context20basic_format_contextE8OutputIt11format_argsN6detail10locale_refE"></span><span id="_CPPv2N3fmt20basic_format_context20basic_format_contextE8OutputIt11format_argsN6detail10locale_refE"></span><span id="fmt::basic_format_context::basic_format_context__OutputIt.format_args.detail::locale_refCE"></span><span class="target" id="classfmt_1_1basic__format__context_1ab32a6df3da0f1f4e2ff8188d1e21e0be"></span><em class="property">constexpr</em> <code class="sig-name descname">basic_format_context</code><span class="sig-paren">(</span><a class="reference internal" href="#_CPPv4I00EN3fmt20basic_format_contextE" title="fmt::basic_format_context::OutputIt">OutputIt</a> <em>out</em>, <a class="reference internal" href="#_CPPv4N3fmt11format_argsE" title="fmt::format_args">format_args</a> <em>ctx_args</em>, detail::locale_ref <em>loc</em> = {}<span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4N3fmt20basic_format_context20basic_format_contextE8OutputIt11format_argsN6detail10locale_refE" title="Permalink to this definition">¶</a><br /></dt> | |
651 <dd><p>Constructs a <code class="docutils literal notranslate"><span class="pre">basic_format_context</span></code> object. </p> | |
652 <p>References to the arguments are stored in the object so make sure they have appropriate lifetimes. </p> | |
653 </dd></dl> | |
654 | |
655 </div> | |
656 </dd></dl> | |
657 | |
658 <dl class="cpp type"> | |
659 <dt id="_CPPv4N3fmt14format_contextE"> | |
660 <span id="_CPPv3N3fmt14format_contextE"></span><span id="_CPPv2N3fmt14format_contextE"></span><span class="target" id="core_8h_1a467d4e330ff42661b03cceaed5a6dfc8"></span><em class="property">using </em><code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">format_context</code> = buffer_context<char><a class="headerlink" href="#_CPPv4N3fmt14format_contextE" title="Permalink to this definition">¶</a><br /></dt> | |
661 <dd></dd></dl> | |
662 | |
663 </section> | |
664 <section id="dynamic-argument-lists"> | |
665 <span id="args-api"></span><h3>Dynamic Argument Lists<a class="headerlink" href="#dynamic-argument-lists" title="Permalink to this headline">¶</a></h3> | |
666 <p>The header <code class="docutils literal notranslate"><span class="pre">fmt/args.h</span></code> provides <code class="docutils literal notranslate"><span class="pre">dynamic_format_arg_store</span></code>, a builder-like | |
667 API that can be used to construct format argument lists dynamically.</p> | |
668 <dl class="cpp class"> | |
669 <dt id="_CPPv4I0EN3fmt24dynamic_format_arg_storeE"> | |
670 <span id="_CPPv3I0EN3fmt24dynamic_format_arg_storeE"></span><span id="_CPPv2I0EN3fmt24dynamic_format_arg_storeE"></span>template<typename <code class="sig-name descname">Context</code>><br /><span class="target" id="classfmt_1_1dynamic__format__arg__store"></span><em class="property">class </em><code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">dynamic_format_arg_store</code><a class="headerlink" href="#_CPPv4I0EN3fmt24dynamic_format_arg_storeE" title="Permalink to this definition">¶</a><br /></dt> | |
671 <dd><p><p><p>A dynamic version of <a class="reference internal" href="#_CPPv4I0DpEN3fmt16format_arg_storeE" title="fmt::format_arg_store"><code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">fmt::format_arg_store</span></code></a>. | |
672 It’s equipped with a storage to potentially temporary objects which lifetimes | |
673 could be shorter than the format arguments object.</p> | |
674 <p>It can be implicitly converted into <a class="reference internal" href="#_CPPv4I0EN3fmt17basic_format_argsE" title="fmt::basic_format_args"><code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">basic_format_args</span></code></a> for passing | |
675 into type-erased formatting functions such as <a class="reference internal" href="#_CPPv4N3fmt7vformatE11string_view11format_args" title="fmt::vformat"><code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">vformat()</span></code></a>.</p> | |
676 </p> | |
677 </p> | |
678 <div class="breathe-sectiondef docutils container"> | |
679 <p class="breathe-sectiondef-title rubric">Public Functions</p> | |
680 <dl class="cpp function"> | |
681 <dt id="_CPPv4I0EN3fmt24dynamic_format_arg_store9push_backEvRK1T"> | |
682 <span id="_CPPv3I0EN3fmt24dynamic_format_arg_store9push_backERK1T"></span><span id="_CPPv2I0EN3fmt24dynamic_format_arg_store9push_backERK1T"></span>template<typename <code class="sig-name descname">T</code>><br /><span class="target" id="classfmt_1_1dynamic__format__arg__store_1af3020ec9bf9450a1d6020be9a19f70d3"></span>void <code class="sig-name descname">push_back</code><span class="sig-paren">(</span><em class="property">const</em> <a class="reference internal" href="#_CPPv4I0EN3fmt24dynamic_format_arg_store9push_backEvRK1T" title="fmt::dynamic_format_arg_store::push_back::T">T</a> &<em>arg</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4I0EN3fmt24dynamic_format_arg_store9push_backEvRK1T" title="Permalink to this definition">¶</a><br /></dt> | |
683 <dd><p><p><p>Adds an argument into the dynamic store for later passing to a formatting | |
684 function.</p> | |
685 <p>Note that custom types and string types (but not string views) are copied | |
686 into the store dynamically allocating memory if necessary.</p> | |
687 <p><strong>Example</strong>:</p> | |
688 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="n">fmt</span><span class="o">::</span><span class="n">dynamic_format_arg_store</span><span class="o"><</span><span class="n">fmt</span><span class="o">::</span><span class="n">format_context</span><span class="o">></span><span class="w"> </span><span class="n">store</span><span class="p">;</span> | |
689 <span class="n">store</span><span class="p">.</span><span class="n">push_back</span><span class="p">(</span><span class="mi">42</span><span class="p">);</span> | |
690 <span class="n">store</span><span class="p">.</span><span class="n">push_back</span><span class="p">(</span><span class="s">"abc"</span><span class="p">);</span> | |
691 <span class="n">store</span><span class="p">.</span><span class="n">push_back</span><span class="p">(</span><span class="mf">1.5f</span><span class="p">);</span> | |
692 <span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="w"> </span><span class="n">result</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">vformat</span><span class="p">(</span><span class="s">"{} and {} and {}"</span><span class="p">,</span><span class="w"> </span><span class="n">store</span><span class="p">);</span> | |
693 </pre></div> | |
694 </div> | |
695 </p> | |
696 </p> | |
697 </dd></dl> | |
698 | |
699 <dl class="cpp function"> | |
700 <dt id="_CPPv4I0EN3fmt24dynamic_format_arg_store9push_backEvNSt17reference_wrapperI1TEE"> | |
701 <span id="_CPPv3I0EN3fmt24dynamic_format_arg_store9push_backENSt17reference_wrapperI1TEE"></span><span id="_CPPv2I0EN3fmt24dynamic_format_arg_store9push_backENSt17reference_wrapperI1TEE"></span>template<typename <code class="sig-name descname">T</code>><br /><span class="target" id="classfmt_1_1dynamic__format__arg__store_1a858e191df4feee6a7796744a6d8182f5"></span>void <code class="sig-name descname">push_back</code><span class="sig-paren">(</span>std::reference_wrapper<<a class="reference internal" href="#_CPPv4I0EN3fmt24dynamic_format_arg_store9push_backEvNSt17reference_wrapperI1TEE" title="fmt::dynamic_format_arg_store::push_back::T">T</a>> <em>arg</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4I0EN3fmt24dynamic_format_arg_store9push_backEvNSt17reference_wrapperI1TEE" title="Permalink to this definition">¶</a><br /></dt> | |
702 <dd><p><p><p>Adds a reference to the argument into the dynamic store for later passing to | |
703 a formatting function.</p> | |
704 <p><strong>Example</strong>:</p> | |
705 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="n">fmt</span><span class="o">::</span><span class="n">dynamic_format_arg_store</span><span class="o"><</span><span class="n">fmt</span><span class="o">::</span><span class="n">format_context</span><span class="o">></span><span class="w"> </span><span class="n">store</span><span class="p">;</span> | |
706 <span class="kt">char</span><span class="w"> </span><span class="n">band</span><span class="p">[]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"Rolling Stones"</span><span class="p">;</span> | |
707 <span class="n">store</span><span class="p">.</span><span class="n">push_back</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">cref</span><span class="p">(</span><span class="n">band</span><span class="p">));</span> | |
708 <span class="n">band</span><span class="p">[</span><span class="mi">9</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="sc">'c'</span><span class="p">;</span><span class="w"> </span><span class="c1">// Changing str affects the output.</span> | |
709 <span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="w"> </span><span class="n">result</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">vformat</span><span class="p">(</span><span class="s">"{}"</span><span class="p">,</span><span class="w"> </span><span class="n">store</span><span class="p">);</span> | |
710 <span class="c1">// result == "Rolling Scones"</span> | |
711 </pre></div> | |
712 </div> | |
713 </p> | |
714 </p> | |
715 </dd></dl> | |
716 | |
717 <dl class="cpp function"> | |
718 <dt id="_CPPv4I0EN3fmt24dynamic_format_arg_store9push_backEvRKN6detail9named_argI9char_type1TEE"> | |
719 <span id="_CPPv3I0EN3fmt24dynamic_format_arg_store9push_backERKN6detail9named_argI9char_type1TEE"></span><span id="_CPPv2I0EN3fmt24dynamic_format_arg_store9push_backERKN6detail9named_argI9char_type1TEE"></span>template<typename <code class="sig-name descname">T</code>><br /><span class="target" id="classfmt_1_1dynamic__format__arg__store_1a55ca65d17f91face9f22e1d23097f94f"></span>void <code class="sig-name descname">push_back</code><span class="sig-paren">(</span><em class="property">const</em> detail::named_arg<char_type, <a class="reference internal" href="#_CPPv4I0EN3fmt24dynamic_format_arg_store9push_backEvRKN6detail9named_argI9char_type1TEE" title="fmt::dynamic_format_arg_store::push_back::T">T</a>> &<em>arg</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4I0EN3fmt24dynamic_format_arg_store9push_backEvRKN6detail9named_argI9char_type1TEE" title="Permalink to this definition">¶</a><br /></dt> | |
720 <dd><p>Adds named argument into the dynamic store for later passing to a formatting function. </p> | |
721 <p><code class="docutils literal notranslate"><span class="pre">std::reference_wrapper</span></code> is supported to avoid copying of the argument. The name is always copied into the store. </p> | |
722 </dd></dl> | |
723 | |
724 <dl class="cpp function"> | |
725 <dt id="_CPPv4N3fmt24dynamic_format_arg_store5clearEv"> | |
726 <span id="_CPPv3N3fmt24dynamic_format_arg_store5clearEv"></span><span id="_CPPv2N3fmt24dynamic_format_arg_store5clearEv"></span><span id="fmt::dynamic_format_arg_store::clear"></span><span class="target" id="classfmt_1_1dynamic__format__arg__store_1ab675b3a51c36b3c07b7f3acb68693dff"></span>void <code class="sig-name descname">clear</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4N3fmt24dynamic_format_arg_store5clearEv" title="Permalink to this definition">¶</a><br /></dt> | |
727 <dd><p>Erase all elements from the store. </p> | |
728 </dd></dl> | |
729 | |
730 <dl class="cpp function"> | |
731 <dt id="_CPPv4N3fmt24dynamic_format_arg_store7reserveE6size_t6size_t"> | |
732 <span id="_CPPv3N3fmt24dynamic_format_arg_store7reserveE6size_t6size_t"></span><span id="_CPPv2N3fmt24dynamic_format_arg_store7reserveE6size_t6size_t"></span><span id="fmt::dynamic_format_arg_store::reserve__s.s"></span><span class="target" id="classfmt_1_1dynamic__format__arg__store_1a86fb8989b4b8a225db5ec1037f534128"></span>void <code class="sig-name descname">reserve</code><span class="sig-paren">(</span>size_t <em>new_cap</em>, size_t <em>new_cap_named</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4N3fmt24dynamic_format_arg_store7reserveE6size_t6size_t" title="Permalink to this definition">¶</a><br /></dt> | |
733 <dd><p><p><p>Reserves space to store at least <em>new_cap</em> arguments including | |
734 <em>new_cap_named</em> named arguments.</p> | |
735 </p> | |
736 </p> | |
737 </dd></dl> | |
738 | |
739 </div> | |
740 </dd></dl> | |
741 | |
742 </section> | |
743 <section id="compatibility"> | |
744 <h3>Compatibility<a class="headerlink" href="#compatibility" title="Permalink to this headline">¶</a></h3> | |
745 <dl class="cpp class"> | |
746 <dt id="_CPPv4I0EN3fmt17basic_string_viewE"> | |
747 <span id="_CPPv3I0EN3fmt17basic_string_viewE"></span><span id="_CPPv2I0EN3fmt17basic_string_viewE"></span>template<typename <code class="sig-name descname">Char</code>><br /><span class="target" id="classfmt_1_1basic__string__view"></span><em class="property">class </em><code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">basic_string_view</code><a class="headerlink" href="#_CPPv4I0EN3fmt17basic_string_viewE" title="Permalink to this definition">¶</a><br /></dt> | |
748 <dd><p>An implementation of <code class="docutils literal notranslate"><span class="pre">std::basic_string_view</span></code> for pre-C++17. </p> | |
749 <p>It provides a subset of the API. <code class="docutils literal notranslate"><span class="pre">fmt::basic_string_view</span></code> is used for format strings even if <code class="docutils literal notranslate"><span class="pre">std::string_view</span></code> is available to prevent issues when a library is compiled with a different <code class="docutils literal notranslate"><span class="pre">-std</span></code> option than the client code (which is not recommended). </p> | |
750 <div class="breathe-sectiondef docutils container"> | |
751 <p class="breathe-sectiondef-title rubric">Public Functions</p> | |
752 <dl class="cpp function"> | |
753 <dt id="_CPPv4N3fmt17basic_string_view17basic_string_viewEPK4Char6size_t"> | |
754 <span id="_CPPv3N3fmt17basic_string_view17basic_string_viewEPK4Char6size_t"></span><span id="_CPPv2N3fmt17basic_string_view17basic_string_viewEPK4Char6size_t"></span><span id="fmt::basic_string_view::basic_string_view__CharCP.sCE"></span><span class="target" id="classfmt_1_1basic__string__view_1a77724577d4a659ea5a1080abe63d847d"></span><em class="property">constexpr</em> <code class="sig-name descname">basic_string_view</code><span class="sig-paren">(</span><em class="property">const</em> <a class="reference internal" href="#_CPPv4I0EN3fmt17basic_string_viewE" title="fmt::basic_string_view::Char">Char</a> *<em>s</em>, size_t <em>count</em><span class="sig-paren">)</span> <em class="property">noexcept</em><a class="headerlink" href="#_CPPv4N3fmt17basic_string_view17basic_string_viewEPK4Char6size_t" title="Permalink to this definition">¶</a><br /></dt> | |
755 <dd><p>Constructs a string reference object from a C string and a size. </p> | |
756 </dd></dl> | |
757 | |
758 <dl class="cpp function"> | |
759 <dt id="_CPPv4N3fmt17basic_string_view17basic_string_viewEPK4Char"> | |
760 <span id="_CPPv3N3fmt17basic_string_view17basic_string_viewEPK4Char"></span><span id="_CPPv2N3fmt17basic_string_view17basic_string_viewEPK4Char"></span><span id="fmt::basic_string_view::basic_string_view__CharCP"></span><span class="target" id="classfmt_1_1basic__string__view_1a027c1e3a6352aa4ad89a1414bbf1c349"></span><code class="sig-name descname">basic_string_view</code><span class="sig-paren">(</span><em class="property">const</em> <a class="reference internal" href="#_CPPv4I0EN3fmt17basic_string_viewE" title="fmt::basic_string_view::Char">Char</a> *<em>s</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4N3fmt17basic_string_view17basic_string_viewEPK4Char" title="Permalink to this definition">¶</a><br /></dt> | |
761 <dd><p><p><p>Constructs a string reference object from a C string computing | |
762 the size with <code class="docutils literal notranslate"><span class="pre">std::char_traits<Char>::length</span></code>.</p> | |
763 </p> | |
764 </p> | |
765 </dd></dl> | |
766 | |
767 <dl class="cpp function"> | |
768 <dt id="_CPPv4I00EN3fmt17basic_string_view17basic_string_viewERKNSt12basic_stringI4Char6Traits5AllocEE"> | |
769 <span id="_CPPv3I00EN3fmt17basic_string_view17basic_string_viewERKNSt12basic_stringI4Char6Traits5AllocEE"></span><span id="_CPPv2I00EN3fmt17basic_string_view17basic_string_viewERKNSt12basic_stringI4Char6Traits5AllocEE"></span>template<typename <code class="sig-name descname">Traits</code>, typename <code class="sig-name descname">Alloc</code>><br /><span class="target" id="classfmt_1_1basic__string__view_1af12a79eae6c2cecea40e52cb193c7608"></span><code class="sig-name descname">basic_string_view</code><span class="sig-paren">(</span><em class="property">const</em> std::basic_string<<a class="reference internal" href="#_CPPv4I0EN3fmt17basic_string_viewE" title="fmt::basic_string_view::Char">Char</a>, <a class="reference internal" href="#_CPPv4I00EN3fmt17basic_string_view17basic_string_viewERKNSt12basic_stringI4Char6Traits5AllocEE" title="fmt::basic_string_view::basic_string_view::Traits">Traits</a>, <a class="reference internal" href="#_CPPv4I00EN3fmt17basic_string_view17basic_string_viewERKNSt12basic_stringI4Char6Traits5AllocEE" title="fmt::basic_string_view::basic_string_view::Alloc">Alloc</a>> &<em>s</em><span class="sig-paren">)</span> <em class="property">noexcept</em><a class="headerlink" href="#_CPPv4I00EN3fmt17basic_string_view17basic_string_viewERKNSt12basic_stringI4Char6Traits5AllocEE" title="Permalink to this definition">¶</a><br /></dt> | |
770 <dd><p>Constructs a string reference from a <code class="docutils literal notranslate"><span class="pre">std::basic_string</span></code> object. </p> | |
771 </dd></dl> | |
772 | |
773 <dl class="cpp function"> | |
774 <dt id="_CPPv4NK3fmt17basic_string_view4dataEv"> | |
775 <span id="_CPPv3NK3fmt17basic_string_view4dataEv"></span><span id="_CPPv2NK3fmt17basic_string_view4dataEv"></span><span id="fmt::basic_string_view::dataCCE"></span><span class="target" id="classfmt_1_1basic__string__view_1a358b32b01d47dfdf17b0f6ff3f8bbe4f"></span><em class="property">constexpr</em> auto <code class="sig-name descname">data</code><span class="sig-paren">(</span><span class="sig-paren">)</span> <em class="property">const</em> <em class="property">noexcept</em> -> <em class="property">const</em> <a class="reference internal" href="#_CPPv4I0EN3fmt17basic_string_viewE" title="fmt::basic_string_view::Char">Char</a>*<a class="headerlink" href="#_CPPv4NK3fmt17basic_string_view4dataEv" title="Permalink to this definition">¶</a><br /></dt> | |
776 <dd><p>Returns a pointer to the string data. </p> | |
777 </dd></dl> | |
778 | |
779 <dl class="cpp function"> | |
780 <dt id="_CPPv4NK3fmt17basic_string_view4sizeEv"> | |
781 <span id="_CPPv3NK3fmt17basic_string_view4sizeEv"></span><span id="_CPPv2NK3fmt17basic_string_view4sizeEv"></span><span id="fmt::basic_string_view::sizeCCE"></span><span class="target" id="classfmt_1_1basic__string__view_1a52d7307059832543f7288803ca78dcbc"></span><em class="property">constexpr</em> auto <code class="sig-name descname">size</code><span class="sig-paren">(</span><span class="sig-paren">)</span> <em class="property">const</em> <em class="property">noexcept</em> -> size_t<a class="headerlink" href="#_CPPv4NK3fmt17basic_string_view4sizeEv" title="Permalink to this definition">¶</a><br /></dt> | |
782 <dd><p>Returns the string size. </p> | |
783 </dd></dl> | |
784 | |
785 </div> | |
786 </dd></dl> | |
787 | |
788 <dl class="cpp type"> | |
789 <dt id="_CPPv4N3fmt11string_viewE"> | |
790 <span id="_CPPv3N3fmt11string_viewE"></span><span id="_CPPv2N3fmt11string_viewE"></span><span class="target" id="core_8h_1ac884b6d263af5b3c1b711ee568225364"></span><em class="property">using </em><code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">string_view</code> = <a class="reference internal" href="#_CPPv4I0EN3fmt17basic_string_viewE" title="fmt::basic_string_view">basic_string_view</a><char><a class="headerlink" href="#_CPPv4N3fmt11string_viewE" title="Permalink to this definition">¶</a><br /></dt> | |
791 <dd></dd></dl> | |
792 | |
793 </section> | |
794 </section> | |
795 <section id="format-api"> | |
796 <span id="id2"></span><h2>Format API<a class="headerlink" href="#format-api" title="Permalink to this headline">¶</a></h2> | |
797 <p><code class="docutils literal notranslate"><span class="pre">fmt/format.h</span></code> defines the full format API providing additional formatting | |
798 functions and locale support.</p> | |
799 <section id="literal-based-api"> | |
800 <h3>Literal-Based API<a class="headerlink" href="#literal-based-api" title="Permalink to this headline">¶</a></h3> | |
801 <p>The following user-defined literals are defined in <code class="docutils literal notranslate"><span class="pre">fmt/format.h</span></code>.</p> | |
802 <dl class="cpp function"> | |
803 <dt id="_CPPv4I_N15detail_exported12fixed_stringEEN3fmtli2_aEDav"> | |
804 <span id="_CPPv3I_N15detail_exported12fixed_stringEEN3fmtli2_aEv"></span><span id="_CPPv2I_N15detail_exported12fixed_stringEEN3fmtli2_aEv"></span>template<detail_exported::fixed_string <code class="sig-name descname">Str</code>><br /><span class="target" id="format_8h_1a61cae931a86f3a5891edf0ff838fee3a"></span><em class="property">constexpr</em> auto <code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">operator""_a</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4I_N15detail_exported12fixed_stringEEN3fmtli2_aEDav" title="Permalink to this definition">¶</a><br /></dt> | |
805 <dd><p><p><p>User-defined literal equivalent of <a class="reference internal" href="#_CPPv4I00EN3fmt3argEN6detail9named_argI4Char1TEEPK4CharRK1T" title="fmt::arg"><code class="xref cpp cpp-func docutils literal notranslate"><span class="pre">fmt::arg()</span></code></a>.</p> | |
806 <p><strong>Example</strong>:</p> | |
807 <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> | |
808 <span class="n">fmt</span><span class="o">::</span><span class="n">print</span><span class="p">(</span><span class="s">"Elapsed time: {s:.2f} seconds"</span><span class="p">,</span><span class="w"> </span><span class="s">"s"</span><span class="n">_a</span><span class="o">=</span><span class="mf">1.23</span><span class="p">);</span> | |
809 </pre></div> | |
810 </div> | |
811 </p> | |
812 </p> | |
813 </dd></dl> | |
814 | |
815 </section> | |
816 <section id="utilities"> | |
817 <h3>Utilities<a class="headerlink" href="#utilities" title="Permalink to this headline">¶</a></h3> | |
818 <dl class="cpp function"> | |
819 <dt id="_CPPv4I0EN3fmt3ptrEPKv1T"> | |
820 <span id="_CPPv3I0EN3fmt3ptrE1T"></span><span id="_CPPv2I0EN3fmt3ptrE1T"></span>template<typename <code class="sig-name descname">T</code>><br /><span class="target" id="format_8h_1ac62203b4bde2a7a7e3a3ef05c33f8675"></span>auto <code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">ptr</code><span class="sig-paren">(</span><a class="reference internal" href="#_CPPv4I0EN3fmt3ptrEPKv1T" title="fmt::ptr::T">T</a> <em>p</em><span class="sig-paren">)</span> -> <em class="property">const</em> void*<a class="headerlink" href="#_CPPv4I0EN3fmt3ptrEPKv1T" title="Permalink to this definition">¶</a><br /></dt> | |
821 <dd><p><p><p>Converts <code class="docutils literal notranslate"><span class="pre">p</span></code> to <code class="docutils literal notranslate"><span class="pre">const</span> <span class="pre">void*</span></code> for pointer formatting.</p> | |
822 <p><strong>Example</strong>:</p> | |
823 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="k">auto</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">"{}"</span><span class="p">,</span><span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">ptr</span><span class="p">(</span><span class="n">p</span><span class="p">));</span> | |
824 </pre></div> | |
825 </div> | |
826 </p> | |
827 </p> | |
828 </dd></dl> | |
829 | |
830 <dl class="cpp function"> | |
831 <dt id="_CPPv4I00EN3fmt3ptrEPKvRKNSt10unique_ptrI1T7DeleterEE"> | |
832 <span id="_CPPv3I00EN3fmt3ptrERKNSt10unique_ptrI1T7DeleterEE"></span><span id="_CPPv2I00EN3fmt3ptrERKNSt10unique_ptrI1T7DeleterEE"></span>template<typename <code class="sig-name descname">T</code>, typename <code class="sig-name descname">Deleter</code>><br /><span class="target" id="format_8h_1a53e1e7c78e3118e81c59f07ec602a6e2"></span>auto <code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">ptr</code><span class="sig-paren">(</span><em class="property">const</em> std::unique_ptr<<a class="reference internal" href="#_CPPv4I00EN3fmt3ptrEPKvRKNSt10unique_ptrI1T7DeleterEE" title="fmt::ptr::T">T</a>, <a class="reference internal" href="#_CPPv4I00EN3fmt3ptrEPKvRKNSt10unique_ptrI1T7DeleterEE" title="fmt::ptr::Deleter">Deleter</a>> &<em>p</em><span class="sig-paren">)</span> -> <em class="property">const</em> void*<a class="headerlink" href="#_CPPv4I00EN3fmt3ptrEPKvRKNSt10unique_ptrI1T7DeleterEE" title="Permalink to this definition">¶</a><br /></dt> | |
833 <dd></dd></dl> | |
834 | |
835 <dl class="cpp function"> | |
836 <dt id="_CPPv4I0EN3fmt3ptrEPKvRKNSt10shared_ptrI1TEE"> | |
837 <span id="_CPPv3I0EN3fmt3ptrERKNSt10shared_ptrI1TEE"></span><span id="_CPPv2I0EN3fmt3ptrERKNSt10shared_ptrI1TEE"></span>template<typename <code class="sig-name descname">T</code>><br /><span class="target" id="format_8h_1ac0a9165f6676ea8fce0c34e7297e53a9"></span>auto <code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">ptr</code><span class="sig-paren">(</span><em class="property">const</em> std::shared_ptr<<a class="reference internal" href="#_CPPv4I0EN3fmt3ptrEPKvRKNSt10shared_ptrI1TEE" title="fmt::ptr::T">T</a>> &<em>p</em><span class="sig-paren">)</span> -> <em class="property">const</em> void*<a class="headerlink" href="#_CPPv4I0EN3fmt3ptrEPKvRKNSt10shared_ptrI1TEE" title="Permalink to this definition">¶</a><br /></dt> | |
838 <dd></dd></dl> | |
839 | |
840 <dl class="cpp function"> | |
841 <dt id="_CPPv4I0EN3fmt10underlyingE12underlying_tI4EnumE4Enum"> | |
842 <span id="_CPPv3I0EN3fmt10underlyingE4Enum"></span><span id="_CPPv2I0EN3fmt10underlyingE4Enum"></span>template<typename <code class="sig-name descname">Enum</code>><br /><span class="target" id="format_8h_1a809639c35a5a0daa5e1cc84c522c75c9"></span><em class="property">constexpr</em> auto <code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">underlying</code><span class="sig-paren">(</span><a class="reference internal" href="#_CPPv4I0EN3fmt10underlyingE12underlying_tI4EnumE4Enum" title="fmt::underlying::Enum">Enum</a> <em>e</em><span class="sig-paren">)</span> <em class="property">noexcept</em> -> underlying_t<<a class="reference internal" href="#_CPPv4I0EN3fmt10underlyingE12underlying_tI4EnumE4Enum" title="fmt::underlying::Enum">Enum</a>><a class="headerlink" href="#_CPPv4I0EN3fmt10underlyingE12underlying_tI4EnumE4Enum" title="Permalink to this definition">¶</a><br /></dt> | |
843 <dd><p><p><p>Converts <code class="docutils literal notranslate"><span class="pre">e</span></code> to the underlying type.</p> | |
844 <p><strong>Example</strong>:</p> | |
845 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="k">enum</span><span class="w"> </span><span class="k">class</span><span class="w"> </span><span class="nc">color</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">red</span><span class="p">,</span><span class="w"> </span><span class="n">green</span><span class="p">,</span><span class="w"> </span><span class="n">blue</span><span class="w"> </span><span class="p">};</span> | |
846 <span class="k">auto</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">"{}"</span><span class="p">,</span><span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">underlying</span><span class="p">(</span><span class="n">color</span><span class="o">::</span><span class="n">red</span><span class="p">));</span> | |
847 </pre></div> | |
848 </div> | |
849 </p> | |
850 </p> | |
851 </dd></dl> | |
852 | |
853 <dl class="cpp function"> | |
854 <dt id="_CPPv4I0EN3fmt9to_stringENSt6stringERK1T"> | |
855 <span id="_CPPv3I0EN3fmt9to_stringERK1T"></span><span id="_CPPv2I0EN3fmt9to_stringERK1T"></span>template<typename <code class="sig-name descname">T</code>><br /><span class="target" id="format_8h_1ae498a7e951bb8f06f53bd6cb4e371633"></span>auto <code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">to_string</code><span class="sig-paren">(</span><em class="property">const</em> <a class="reference internal" href="#_CPPv4I0EN3fmt9to_stringENSt6stringERK1T" title="fmt::to_string::T">T</a> &<em>value</em><span class="sig-paren">)</span> -> std::string<a class="headerlink" href="#_CPPv4I0EN3fmt9to_stringENSt6stringERK1T" title="Permalink to this definition">¶</a><br /></dt> | |
856 <dd><p><p><p>Converts <em>value</em> to <code class="docutils literal notranslate"><span class="pre">std::string</span></code> using the default format for type <em>T</em>.</p> | |
857 <p><strong>Example</strong>:</p> | |
858 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf"><fmt/format.h></span> | |
859 | |
860 <span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="w"> </span><span class="n">answer</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">to_string</span><span class="p">(</span><span class="mi">42</span><span class="p">);</span> | |
861 </pre></div> | |
862 </div> | |
863 </p> | |
864 </p> | |
865 </dd></dl> | |
866 | |
867 <dl class="cpp function"> | |
868 <dt id="_CPPv4I0EN3fmt4joinE9join_viewIN6detail10iterator_tI5RangeEEN6detail10sentinel_tI5RangeEEERR5Range11string_view"> | |
869 <span id="_CPPv3I0EN3fmt4joinERR5Range11string_view"></span><span id="_CPPv2I0EN3fmt4joinERR5Range11string_view"></span>template<typename <code class="sig-name descname">Range</code>><br /><span class="target" id="format_8h_1a4f98d49e3396fd35aba376cb0f40a882"></span>auto <code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">join</code><span class="sig-paren">(</span><a class="reference internal" href="#_CPPv4I0EN3fmt4joinE9join_viewIN6detail10iterator_tI5RangeEEN6detail10sentinel_tI5RangeEEERR5Range11string_view" title="fmt::join::Range">Range</a> &&<em>range</em>, <a class="reference internal" href="#_CPPv4N3fmt11string_viewE" title="fmt::string_view">string_view</a> <em>sep</em><span class="sig-paren">)</span> -> join_view<detail::iterator_t<<a class="reference internal" href="#_CPPv4I0EN3fmt4joinE9join_viewIN6detail10iterator_tI5RangeEEN6detail10sentinel_tI5RangeEEERR5Range11string_view" title="fmt::join::Range">Range</a>>, detail::sentinel_t<<a class="reference internal" href="#_CPPv4I0EN3fmt4joinE9join_viewIN6detail10iterator_tI5RangeEEN6detail10sentinel_tI5RangeEEERR5Range11string_view" title="fmt::join::Range">Range</a>>><a class="headerlink" href="#_CPPv4I0EN3fmt4joinE9join_viewIN6detail10iterator_tI5RangeEEN6detail10sentinel_tI5RangeEEERR5Range11string_view" title="Permalink to this definition">¶</a><br /></dt> | |
870 <dd><p><p><p>Returns a view that formats <a class="reference internal" href="#_CPPv4I0EN3fmt4joinE9join_viewIN6detail10iterator_tI5RangeEEN6detail10sentinel_tI5RangeEEERR5Range11string_view" title="fmt::join::range"><code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">range</span></code></a> with elements separated by <a class="reference internal" href="#_CPPv4I0EN3fmt4joinE9join_viewIN6detail10iterator_tI5RangeEEN6detail10sentinel_tI5RangeEEERR5Range11string_view" title="fmt::join::sep"><code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">sep</span></code></a>.</p> | |
871 <p><strong>Example</strong>:</p> | |
872 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="n">std</span><span class="o">::</span><span class="n">vector</span><span class="o"><</span><span class="kt">int</span><span class="o">></span><span class="w"> </span><span class="n">v</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">};</span> | |
873 <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">fmt</span><span class="o">::</span><span class="n">join</span><span class="p">(</span><span class="n">v</span><span class="p">,</span><span class="w"> </span><span class="s">", "</span><span class="p">));</span> | |
874 <span class="c1">// Output: "1, 2, 3"</span> | |
875 </pre></div> | |
876 </div> | |
877 <p><code class="docutils literal notranslate"><span class="pre">fmt::join</span></code> applies passed format specifiers to the range elements:</p> | |
878 <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">"{:02}"</span><span class="p">,</span><span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">join</span><span class="p">(</span><span class="n">v</span><span class="p">,</span><span class="w"> </span><span class="s">", "</span><span class="p">));</span> | |
879 <span class="c1">// Output: "01, 02, 03"</span> | |
880 </pre></div> | |
881 </div> | |
882 </p> | |
883 </p> | |
884 </dd></dl> | |
885 | |
886 <dl class="cpp function"> | |
887 <dt id="_CPPv4I00EN3fmt4joinE9join_viewI2It8SentinelE2It8Sentinel11string_view"> | |
888 <span id="_CPPv3I00EN3fmt4joinE2It8Sentinel11string_view"></span><span id="_CPPv2I00EN3fmt4joinE2It8Sentinel11string_view"></span>template<typename <code class="sig-name descname">It</code>, typename <code class="sig-name descname">Sentinel</code>><br /><span class="target" id="format_8h_1a0d920c12aba189c116ca1a33aee29f7f"></span>auto <code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">join</code><span class="sig-paren">(</span><a class="reference internal" href="#_CPPv4I00EN3fmt4joinE9join_viewI2It8SentinelE2It8Sentinel11string_view" title="fmt::join::It">It</a> <em>begin</em>, <a class="reference internal" href="#_CPPv4I00EN3fmt4joinE9join_viewI2It8SentinelE2It8Sentinel11string_view" title="fmt::join::Sentinel">Sentinel</a> <em>end</em>, <a class="reference internal" href="#_CPPv4N3fmt11string_viewE" title="fmt::string_view">string_view</a> <em>sep</em><span class="sig-paren">)</span> -> join_view<<a class="reference internal" href="#_CPPv4I00EN3fmt4joinE9join_viewI2It8SentinelE2It8Sentinel11string_view" title="fmt::join::It">It</a>, <a class="reference internal" href="#_CPPv4I00EN3fmt4joinE9join_viewI2It8SentinelE2It8Sentinel11string_view" title="fmt::join::Sentinel">Sentinel</a>><a class="headerlink" href="#_CPPv4I00EN3fmt4joinE9join_viewI2It8SentinelE2It8Sentinel11string_view" title="Permalink to this definition">¶</a><br /></dt> | |
889 <dd><p>Returns a view that formats the iterator range <code class="docutils literal notranslate"><span class="pre">[begin,</span> <span class="pre">end)</span></code> with elements separated by <code class="docutils literal notranslate"><span class="pre">sep</span></code>. </p> | |
890 </dd></dl> | |
891 | |
892 <dl class="cpp function"> | |
893 <dt id="_CPPv4I0EN3fmt12group_digitsE17group_digits_viewI1TE1T"> | |
894 <span id="_CPPv3I0EN3fmt12group_digitsE1T"></span><span id="_CPPv2I0EN3fmt12group_digitsE1T"></span>template<typename <code class="sig-name descname">T</code>><br /><span class="target" id="format_8h_1a229cf9b3f39965821d68af045a5f6cc4"></span>auto <code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">group_digits</code><span class="sig-paren">(</span><a class="reference internal" href="#_CPPv4I0EN3fmt12group_digitsE17group_digits_viewI1TE1T" title="fmt::group_digits::T">T</a> <em>value</em><span class="sig-paren">)</span> -> group_digits_view<<a class="reference internal" href="#_CPPv4I0EN3fmt12group_digitsE17group_digits_viewI1TE1T" title="fmt::group_digits::T">T</a>><a class="headerlink" href="#_CPPv4I0EN3fmt12group_digitsE17group_digits_viewI1TE1T" title="Permalink to this definition">¶</a><br /></dt> | |
895 <dd><p><p><p>Returns a view that formats an integer value using ‘,’ as a locale-independent | |
896 thousands separator.</p> | |
897 <p><strong>Example</strong>:</p> | |
898 <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">fmt</span><span class="o">::</span><span class="n">group_digits</span><span class="p">(</span><span class="mi">12345</span><span class="p">));</span> | |
899 <span class="c1">// Output: "12,345"</span> | |
900 </pre></div> | |
901 </div> | |
902 </p> | |
903 </p> | |
904 </dd></dl> | |
905 | |
906 <dl class="cpp class"> | |
907 <dt id="_CPPv4I0EN3fmt6detail6bufferE"> | |
908 <span id="_CPPv3I0EN3fmt6detail6bufferE"></span><span id="_CPPv2I0EN3fmt6detail6bufferE"></span>template<typename <code class="sig-name descname">T</code>><br /><span class="target" id="classfmt_1_1detail_1_1buffer"></span><em class="property">class </em><code class="sig-prename descclassname">fmt::detail<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">buffer</code><a class="headerlink" href="#_CPPv4I0EN3fmt6detail6bufferE" title="Permalink to this definition">¶</a><br /></dt> | |
909 <dd><p><p><p>A contiguous memory buffer with an optional growing ability. It is an internal | |
910 class and shouldn’t be used directly, only via <a class="reference internal" href="#_CPPv4I0_6size_t0EN3fmt19basic_memory_bufferE" title="fmt::basic_memory_buffer"><code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">basic_memory_buffer</span></code></a>.</p> | |
911 </p> | |
912 </p> | |
913 <p>Subclassed by <a class="reference internal" href="#classfmt_1_1basic__memory__buffer"><span class="std std-ref">fmt::basic_memory_buffer< bigit, bigits_capacity ></span></a>, <a class="reference internal" href="#classfmt_1_1basic__memory__buffer"><span class="std std-ref">fmt::basic_memory_buffer< wchar_t ></span></a>, <a class="reference internal" href="#classfmt_1_1basic__memory__buffer"><span class="std std-ref">fmt::basic_memory_buffer< T, SIZE, Allocator ></span></a>, fmt::detail::counting_buffer< T >, fmt::detail::iterator_buffer< OutputIt, T, Traits >, fmt::detail::iterator_buffer< T *, T >, fmt::detail::iterator_buffer< T *, T, fixed_buffer_traits ></p> | |
914 <div class="breathe-sectiondef docutils container"> | |
915 <p class="breathe-sectiondef-title rubric">Public Functions</p> | |
916 <dl class="cpp function"> | |
917 <dt id="_CPPv4NK3fmt6detail6buffer4sizeEv"> | |
918 <span id="_CPPv3NK3fmt6detail6buffer4sizeEv"></span><span id="_CPPv2NK3fmt6detail6buffer4sizeEv"></span><span id="fmt::detail::buffer::sizeCCE"></span><span class="target" id="classfmt_1_1detail_1_1buffer_1a490109c8af99a7bbc522bab73c6d6a3f"></span><em class="property">constexpr</em> auto <code class="sig-name descname">size</code><span class="sig-paren">(</span><span class="sig-paren">)</span> <em class="property">const</em> <em class="property">noexcept</em> -> size_t<a class="headerlink" href="#_CPPv4NK3fmt6detail6buffer4sizeEv" title="Permalink to this definition">¶</a><br /></dt> | |
919 <dd><p>Returns the size of this buffer. </p> | |
920 </dd></dl> | |
921 | |
922 <dl class="cpp function"> | |
923 <dt id="_CPPv4NK3fmt6detail6buffer8capacityEv"> | |
924 <span id="_CPPv3NK3fmt6detail6buffer8capacityEv"></span><span id="_CPPv2NK3fmt6detail6buffer8capacityEv"></span><span id="fmt::detail::buffer::capacityCCE"></span><span class="target" id="classfmt_1_1detail_1_1buffer_1af35c750f68db5aee87528c56ad773fc3"></span><em class="property">constexpr</em> auto <code class="sig-name descname">capacity</code><span class="sig-paren">(</span><span class="sig-paren">)</span> <em class="property">const</em> <em class="property">noexcept</em> -> size_t<a class="headerlink" href="#_CPPv4NK3fmt6detail6buffer8capacityEv" title="Permalink to this definition">¶</a><br /></dt> | |
925 <dd><p>Returns the capacity of this buffer. </p> | |
926 </dd></dl> | |
927 | |
928 <dl class="cpp function"> | |
929 <dt id="_CPPv4N3fmt6detail6buffer4dataEv"> | |
930 <span id="_CPPv3N3fmt6detail6buffer4dataEv"></span><span id="_CPPv2N3fmt6detail6buffer4dataEv"></span><span id="fmt::detail::buffer::data"></span><span class="target" id="classfmt_1_1detail_1_1buffer_1ad520da92b9f427d5a1943c0806f55d99"></span>auto <code class="sig-name descname">data</code><span class="sig-paren">(</span><span class="sig-paren">)</span> <em class="property">noexcept</em> -> <a class="reference internal" href="#_CPPv4I0EN3fmt6detail6bufferE" title="fmt::detail::buffer::T">T</a>*<a class="headerlink" href="#_CPPv4N3fmt6detail6buffer4dataEv" title="Permalink to this definition">¶</a><br /></dt> | |
931 <dd><p>Returns a pointer to the buffer data (not null-terminated). </p> | |
932 </dd></dl> | |
933 | |
934 <dl class="cpp function"> | |
935 <dt id="_CPPv4N3fmt6detail6buffer5clearEv"> | |
936 <span id="_CPPv3N3fmt6detail6buffer5clearEv"></span><span id="_CPPv2N3fmt6detail6buffer5clearEv"></span><span id="fmt::detail::buffer::clear"></span><span class="target" id="classfmt_1_1detail_1_1buffer_1ac64497e345116bae746b638cedb7ac20"></span>void <code class="sig-name descname">clear</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4N3fmt6detail6buffer5clearEv" title="Permalink to this definition">¶</a><br /></dt> | |
937 <dd><p>Clears this buffer. </p> | |
938 </dd></dl> | |
939 | |
940 <dl class="cpp function"> | |
941 <dt id="_CPPv4I0EN3fmt6detail6buffer6appendEvPK1UPK1U"> | |
942 <span id="_CPPv3I0EN3fmt6detail6buffer6appendEPK1UPK1U"></span><span id="_CPPv2I0EN3fmt6detail6buffer6appendEPK1UPK1U"></span>template<typename <code class="sig-name descname">U</code>><br /><span class="target" id="classfmt_1_1detail_1_1buffer_1afae920b7b90cc657d4bd9df9ceac4c2b"></span>void <code class="sig-name descname">append</code><span class="sig-paren">(</span><em class="property">const</em> <a class="reference internal" href="#_CPPv4I0EN3fmt6detail6buffer6appendEvPK1UPK1U" title="fmt::detail::buffer::append::U">U</a> *<em>begin</em>, <em class="property">const</em> <a class="reference internal" href="#_CPPv4I0EN3fmt6detail6buffer6appendEvPK1UPK1U" title="fmt::detail::buffer::append::U">U</a> *<em>end</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4I0EN3fmt6detail6buffer6appendEvPK1UPK1U" title="Permalink to this definition">¶</a><br /></dt> | |
943 <dd><p>Appends data to the end of the buffer. </p> | |
944 </dd></dl> | |
945 | |
946 </div> | |
947 </dd></dl> | |
948 | |
949 <dl class="cpp class"> | |
950 <dt id="_CPPv4I0_6size_t0EN3fmt19basic_memory_bufferE"> | |
951 <span id="_CPPv3I0_6size_t0EN3fmt19basic_memory_bufferE"></span><span id="_CPPv2I0_6size_t0EN3fmt19basic_memory_bufferE"></span>template<typename <code class="sig-name descname">T</code>, size_t <code class="sig-name descname">SIZE</code> = inline_buffer_size, typename <code class="sig-name descname">Allocator</code> = std::allocator<<a class="reference internal" href="#_CPPv4I0_6size_t0EN3fmt19basic_memory_bufferE" title="fmt::basic_memory_buffer::T">T</a>>><br /><span class="target" id="classfmt_1_1basic__memory__buffer"></span><em class="property">class </em><code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">basic_memory_buffer</code> : <em class="property">public</em> fmt::detail::<a class="reference internal" href="#_CPPv4I0EN3fmt6detail6bufferE" title="fmt::detail::buffer">buffer</a><<a class="reference internal" href="#_CPPv4I0_6size_t0EN3fmt19basic_memory_bufferE" title="fmt::basic_memory_buffer::T">T</a>><a class="headerlink" href="#_CPPv4I0_6size_t0EN3fmt19basic_memory_bufferE" title="Permalink to this definition">¶</a><br /></dt> | |
952 <dd><p><p><p>A dynamically growing memory buffer for trivially copyable/constructible types | |
953 with the first <code class="docutils literal notranslate"><span class="pre">SIZE</span></code> elements stored in the object itself.</p> | |
954 <p>You can use the <code class="docutils literal notranslate"><span class="pre">memory_buffer</span></code> type alias for <code class="docutils literal notranslate"><span class="pre">char</span></code> instead.</p> | |
955 <p><strong>Example</strong>:</p> | |
956 <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> | |
957 <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><span class="w"> </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> | |
958 </pre></div> | |
959 </div> | |
960 <p>This will append the following output to the <code class="docutils literal notranslate"><span class="pre">out</span></code> object:</p> | |
961 <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>The answer is 42. | |
962 </pre></div> | |
963 </div> | |
964 <p>The output can be converted to an <code class="docutils literal notranslate"><span class="pre">std::string</span></code> with <code class="docutils literal notranslate"><span class="pre">to_string(out)</span></code>.</p> | |
965 </p> | |
966 </p> | |
967 <div class="breathe-sectiondef docutils container"> | |
968 <p class="breathe-sectiondef-title rubric">Public Functions</p> | |
969 <dl class="cpp function"> | |
970 <dt id="_CPPv4N3fmt19basic_memory_buffer19basic_memory_bufferERR19basic_memory_buffer"> | |
971 <span id="_CPPv3N3fmt19basic_memory_buffer19basic_memory_bufferERR19basic_memory_buffer"></span><span id="_CPPv2N3fmt19basic_memory_buffer19basic_memory_bufferERR19basic_memory_buffer"></span><span id="fmt::basic_memory_buffer::basic_memory_buffer__basic_memory_bufferRR"></span><span class="target" id="classfmt_1_1basic__memory__buffer_1aec38f6a7ca917da114e568bc15bc80f6"></span><code class="sig-name descname">basic_memory_buffer</code><span class="sig-paren">(</span><a class="reference internal" href="#_CPPv4N3fmt19basic_memory_buffer19basic_memory_bufferERR19basic_memory_buffer" title="fmt::basic_memory_buffer::basic_memory_buffer">basic_memory_buffer</a> &&<em>other</em><span class="sig-paren">)</span> <em class="property">noexcept</em><a class="headerlink" href="#_CPPv4N3fmt19basic_memory_buffer19basic_memory_bufferERR19basic_memory_buffer" title="Permalink to this definition">¶</a><br /></dt> | |
972 <dd><p><p><p>Constructs a <a class="reference internal" href="#_CPPv4I0_6size_t0EN3fmt19basic_memory_bufferE" title="fmt::basic_memory_buffer"><code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">fmt::basic_memory_buffer</span></code></a> object moving the content | |
973 of the other object to it.</p> | |
974 </p> | |
975 </p> | |
976 </dd></dl> | |
977 | |
978 <dl class="cpp function"> | |
979 <dt id="_CPPv4N3fmt19basic_memory_bufferaSERR19basic_memory_buffer"> | |
980 <span id="_CPPv3N3fmt19basic_memory_bufferaSERR19basic_memory_buffer"></span><span id="_CPPv2N3fmt19basic_memory_bufferaSERR19basic_memory_buffer"></span><span id="fmt::basic_memory_buffer::assign-operator__basic_memory_bufferRR"></span><span class="target" id="classfmt_1_1basic__memory__buffer_1a4aba406807261c3f67426706f788bc83"></span>auto <code class="sig-name descname">operator=</code><span class="sig-paren">(</span><a class="reference internal" href="#_CPPv4I0_6size_t0EN3fmt19basic_memory_bufferE" title="fmt::basic_memory_buffer">basic_memory_buffer</a> &&<em>other</em><span class="sig-paren">)</span> <em class="property">noexcept</em> -> <a class="reference internal" href="#_CPPv4I0_6size_t0EN3fmt19basic_memory_bufferE" title="fmt::basic_memory_buffer">basic_memory_buffer</a>&<a class="headerlink" href="#_CPPv4N3fmt19basic_memory_bufferaSERR19basic_memory_buffer" title="Permalink to this definition">¶</a><br /></dt> | |
981 <dd><p><p><p>Moves the content of the other <code class="docutils literal notranslate"><span class="pre">basic_memory_buffer</span></code> object to this one.</p> | |
982 </p> | |
983 </p> | |
984 </dd></dl> | |
985 | |
986 <dl class="cpp function"> | |
987 <dt id="_CPPv4N3fmt19basic_memory_buffer6resizeE6size_t"> | |
988 <span id="_CPPv3N3fmt19basic_memory_buffer6resizeE6size_t"></span><span id="_CPPv2N3fmt19basic_memory_buffer6resizeE6size_t"></span><span id="fmt::basic_memory_buffer::resize__s"></span><span class="target" id="classfmt_1_1basic__memory__buffer_1a29692fe33fa3b6a0a6af43e2368b80be"></span>void <code class="sig-name descname">resize</code><span class="sig-paren">(</span>size_t <em>count</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4N3fmt19basic_memory_buffer6resizeE6size_t" title="Permalink to this definition">¶</a><br /></dt> | |
989 <dd><p>Resizes the buffer to contain <em>count</em> elements. </p> | |
990 <p>If T is a POD type new elements may not be initialized. </p> | |
991 </dd></dl> | |
992 | |
993 <dl class="cpp function"> | |
994 <dt id="_CPPv4N3fmt19basic_memory_buffer7reserveE6size_t"> | |
995 <span id="_CPPv3N3fmt19basic_memory_buffer7reserveE6size_t"></span><span id="_CPPv2N3fmt19basic_memory_buffer7reserveE6size_t"></span><span id="fmt::basic_memory_buffer::reserve__s"></span><span class="target" id="classfmt_1_1basic__memory__buffer_1a8398ff2d3ab710d960b32d5695680551"></span>void <code class="sig-name descname">reserve</code><span class="sig-paren">(</span>size_t <em>new_capacity</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4N3fmt19basic_memory_buffer7reserveE6size_t" title="Permalink to this definition">¶</a><br /></dt> | |
996 <dd><p>Increases the buffer capacity to <em>new_capacity</em>. </p> | |
997 </dd></dl> | |
998 | |
999 </div> | |
1000 <div class="breathe-sectiondef docutils container"> | |
1001 <p class="breathe-sectiondef-title rubric">Protected Functions</p> | |
1002 <dl class="cpp function"> | |
1003 <dt id="_CPPv4N3fmt19basic_memory_buffer4growE6size_t"> | |
1004 <span id="_CPPv3N3fmt19basic_memory_buffer4growE6size_t"></span><span id="_CPPv2N3fmt19basic_memory_buffer4growE6size_t"></span><span id="fmt::basic_memory_buffer::grow__s"></span><span class="target" id="classfmt_1_1basic__memory__buffer_1aeca96953f3c076256cf069c6b0dfef07"></span>void <code class="sig-name descname">grow</code><span class="sig-paren">(</span>size_t <em>size</em><span class="sig-paren">)</span> <em class="property">override</em><a class="headerlink" href="#_CPPv4N3fmt19basic_memory_buffer4growE6size_t" title="Permalink to this definition">¶</a><br /></dt> | |
1005 <dd><p>Increases the buffer capacity to hold at least <em>capacity</em> elements. </p> | |
1006 </dd></dl> | |
1007 | |
1008 </div> | |
1009 </dd></dl> | |
1010 | |
1011 </section> | |
1012 <section id="system-errors"> | |
1013 <h3>System Errors<a class="headerlink" href="#system-errors" title="Permalink to this headline">¶</a></h3> | |
1014 <p>{fmt} does not use <code class="docutils literal notranslate"><span class="pre">errno</span></code> to communicate errors to the user, but it may call | |
1015 system functions which set <code class="docutils literal notranslate"><span class="pre">errno</span></code>. Users should not make any assumptions | |
1016 about the value of <code class="docutils literal notranslate"><span class="pre">errno</span></code> being preserved by library functions.</p> | |
1017 <dl class="cpp function"> | |
1018 <dt id="_CPPv4IDpEN3fmt12system_errorENSt12system_errorEi13format_stringIDp1TEDpRR1T"> | |
1019 <span id="_CPPv3IDpEN3fmt12system_errorEi13format_stringIDp1TEDpRR1T"></span><span id="_CPPv2IDpEN3fmt12system_errorEi13format_stringIDp1TEDpRR1T"></span>template<typename ...<code class="sig-name descname">T</code>><br /><span class="target" id="format_8h_1aa2da9f32c148ea5b56bd8e744a428d28"></span>auto <code class="sig-prename descclassname"><a class="reference internal" href="#_CPPv4IDpEN3fmt12system_errorENSt12system_errorEi13format_stringIDp1TEDpRR1T" title="fmt::system_error::fmt">fmt</a><code class="sig-prename descclassname">::</code></code><code class="sig-name descname">system_error</code><span class="sig-paren">(</span>int <em>error_code</em>, <a class="reference internal" href="#_CPPv4IDpEN3fmt13format_stringE" title="fmt::format_string">format_string</a><<a class="reference internal" href="#_CPPv4IDpEN3fmt12system_errorENSt12system_errorEi13format_stringIDp1TEDpRR1T" title="fmt::system_error::T">T</a>...> <em>fmt</em>, <a class="reference internal" href="#_CPPv4IDpEN3fmt12system_errorENSt12system_errorEi13format_stringIDp1TEDpRR1T" title="fmt::system_error::T">T</a>&&... <em>args</em><span class="sig-paren">)</span> -> std::system_error<a class="headerlink" href="#_CPPv4IDpEN3fmt12system_errorENSt12system_errorEi13format_stringIDp1TEDpRR1T" title="Permalink to this definition">¶</a><br /></dt> | |
1020 <dd><p><p><p>Constructs <code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">std::system_error</span></code> with a message formatted with | |
1021 <code class="docutils literal notranslate"><span class="pre">fmt::format(fmt,</span> <span class="pre">args...)</span></code>. | |
1022 <em>error_code</em> is a system error code as given by <code class="docutils literal notranslate"><span class="pre">errno</span></code>.</p> | |
1023 <p><strong>Example</strong>:</p> | |
1024 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="c1">// This throws std::system_error with the description</span> | |
1025 <span class="c1">// cannot open file 'madeup': No such file or directory</span> | |
1026 <span class="c1">// or similar (system message may vary).</span> | |
1027 <span class="k">const</span><span class="w"> </span><span class="kt">char</span><span class="o">*</span><span class="w"> </span><span class="n">filename</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"madeup"</span><span class="p">;</span> | |
1028 <span class="n">std</span><span class="o">::</span><span class="kt">FILE</span><span class="o">*</span><span class="w"> </span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">fopen</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span><span class="w"> </span><span class="s">"r"</span><span class="p">);</span> | |
1029 <span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="o">!</span><span class="n">file</span><span class="p">)</span> | |
1030 <span class="w"> </span><span class="k">throw</span><span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">system_error</span><span class="p">(</span><span class="n">errno</span><span class="p">,</span><span class="w"> </span><span class="s">"cannot open file '{}'"</span><span class="p">,</span><span class="w"> </span><span class="n">filename</span><span class="p">);</span> | |
1031 </pre></div> | |
1032 </div> | |
1033 </p> | |
1034 </p> | |
1035 </dd></dl> | |
1036 | |
1037 <dl class="cpp function"> | |
1038 <dt id="_CPPv4N3fmt19format_system_errorERN6detail6bufferIcEEiPKc"> | |
1039 <span id="_CPPv3N3fmt19format_system_errorERN6detail6bufferIcEEiPKc"></span><span id="_CPPv2N3fmt19format_system_errorERN6detail6bufferIcEEiPKc"></span><span id="fmt::format_system_error__detail::buffer:c:R.i.cCP"></span><span class="target" id="format_8h_1a51bce415ec78dfa92c6acecb16a69640"></span>void <code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">format_system_error</code><span class="sig-paren">(</span>detail::<a class="reference internal" href="#_CPPv4I0EN3fmt6detail6bufferE" title="fmt::detail::buffer">buffer</a><char> &<em>out</em>, int <em>error_code</em>, <em class="property">const</em> char *<em>message</em><span class="sig-paren">)</span> <em class="property">noexcept</em><a class="headerlink" href="#_CPPv4N3fmt19format_system_errorERN6detail6bufferIcEEiPKc" title="Permalink to this definition">¶</a><br /></dt> | |
1040 <dd><p><p><p>Formats an error message for an error returned by an operating system or a | |
1041 language runtime, for example a file opening error, and writes it to <em>out</em>. | |
1042 The format is the same as the one used by <code class="docutils literal notranslate"><span class="pre">std::system_error(ec,</span> <span class="pre">message)</span></code> | |
1043 where <code class="docutils literal notranslate"><span class="pre">ec</span></code> is <code class="docutils literal notranslate"><span class="pre">std::error_code(error_code,</span> <span class="pre">std::generic_category()})</span></code>. | |
1044 It is implementation-defined but normally looks like:</p> | |
1045 <pre class="literal-block"><em><message></em>: <em><system-message></em></pre> | |
1046 <p>where <em><message></em> is the passed message and <em><system-message></em> is the system | |
1047 message corresponding to the error code. | |
1048 <em>error_code</em> is a system error code as given by <code class="docutils literal notranslate"><span class="pre">errno</span></code>.</p> | |
1049 </p> | |
1050 </p> | |
1051 </dd></dl> | |
1052 | |
1053 </section> | |
1054 <section id="custom-allocators"> | |
1055 <h3>Custom Allocators<a class="headerlink" href="#custom-allocators" title="Permalink to this headline">¶</a></h3> | |
1056 <p>The {fmt} library supports custom dynamic memory allocators. | |
1057 A custom allocator class can be specified as a template argument to | |
1058 <a class="reference internal" href="#_CPPv4I0_6size_t0EN3fmt19basic_memory_bufferE" title="fmt::basic_memory_buffer"><code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">fmt::basic_memory_buffer</span></code></a>:</p> | |
1059 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="k">using</span><span class="w"> </span><span class="n">custom_memory_buffer</span><span class="w"> </span><span class="o">=</span> | |
1060 <span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">basic_memory_buffer</span><span class="o"><</span><span class="kt">char</span><span class="p">,</span><span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">inline_buffer_size</span><span class="p">,</span><span class="w"> </span><span class="n">custom_allocator</span><span class="o">></span><span class="p">;</span> | |
1061 </pre></div> | |
1062 </div> | |
1063 <p>It is also possible to write a formatting function that uses a custom | |
1064 allocator:</p> | |
1065 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="k">using</span><span class="w"> </span><span class="n">custom_string</span><span class="w"> </span><span class="o">=</span> | |
1066 <span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">basic_string</span><span class="o"><</span><span class="kt">char</span><span class="p">,</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">char_traits</span><span class="o"><</span><span class="kt">char</span><span class="o">></span><span class="p">,</span><span class="w"> </span><span class="n">custom_allocator</span><span class="o">></span><span class="p">;</span> | |
1067 | |
1068 <span class="n">custom_string</span><span class="w"> </span><span class="nf">vformat</span><span class="p">(</span><span class="n">custom_allocator</span><span class="w"> </span><span class="n">alloc</span><span class="p">,</span><span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">string_view</span><span class="w"> </span><span class="n">format_str</span><span class="p">,</span> | |
1069 <span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">format_args</span><span class="w"> </span><span class="n">args</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> | |
1070 <span class="w"> </span><span class="k">auto</span><span class="w"> </span><span class="n">buf</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">custom_memory_buffer</span><span class="p">(</span><span class="n">alloc</span><span class="p">);</span> | |
1071 <span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">vformat_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">buf</span><span class="p">),</span><span class="w"> </span><span class="n">format_str</span><span class="p">,</span><span class="w"> </span><span class="n">args</span><span class="p">);</span> | |
1072 <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">custom_string</span><span class="p">(</span><span class="n">buf</span><span class="p">.</span><span class="n">data</span><span class="p">(),</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">size</span><span class="p">(),</span><span class="w"> </span><span class="n">alloc</span><span class="p">);</span> | |
1073 <span class="p">}</span> | |
1074 | |
1075 <span class="k">template</span><span class="w"> </span><span class="o"><</span><span class="k">typename</span><span class="w"> </span><span class="p">...</span><span class="n">Args</span><span class="o">></span> | |
1076 <span class="kr">inline</span><span class="w"> </span><span class="n">custom_string</span><span class="w"> </span><span class="n">format</span><span class="p">(</span><span class="n">custom_allocator</span><span class="w"> </span><span class="n">alloc</span><span class="p">,</span> | |
1077 <span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">string_view</span><span class="w"> </span><span class="n">format_str</span><span class="p">,</span> | |
1078 <span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">Args</span><span class="o">&</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="n">args</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> | |
1079 <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">vformat</span><span class="p">(</span><span class="n">alloc</span><span class="p">,</span><span class="w"> </span><span class="n">format_str</span><span class="p">,</span><span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">make_format_args</span><span class="p">(</span><span class="n">args</span><span class="p">...));</span> | |
1080 <span class="p">}</span> | |
1081 </pre></div> | |
1082 </div> | |
1083 <p>The allocator will be used for the output container only. Formatting functions | |
1084 normally don’t do any allocations for built-in and string types except for | |
1085 non-default floating-point formatting that occasionally falls back on | |
1086 <code class="docutils literal notranslate"><span class="pre">sprintf</span></code>.</p> | |
1087 </section> | |
1088 <section id="locale"> | |
1089 <h3>Locale<a class="headerlink" href="#locale" title="Permalink to this headline">¶</a></h3> | |
1090 <p>All formatting is locale-independent by default. Use the <code class="docutils literal notranslate"><span class="pre">'L'</span></code> format | |
1091 specifier to insert the appropriate number separator characters from the | |
1092 locale:</p> | |
1093 <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> | |
1094 <span class="cp">#include</span><span class="w"> </span><span class="cpf"><locale></span> | |
1095 | |
1096 <span class="n">std</span><span class="o">::</span><span class="n">locale</span><span class="o">::</span><span class="n">global</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">locale</span><span class="p">(</span><span class="s">"en_US.UTF-8"</span><span class="p">));</span> | |
1097 <span class="k">auto</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">"{:L}"</span><span class="p">,</span><span class="w"> </span><span class="mi">1000000</span><span class="p">);</span><span class="w"> </span><span class="c1">// s == "1,000,000"</span> | |
1098 </pre></div> | |
1099 </div> | |
1100 <p><code class="docutils literal notranslate"><span class="pre">fmt/format.h</span></code> provides the following overloads of formatting functions that | |
1101 take <code class="docutils literal notranslate"><span class="pre">std::locale</span></code> as a parameter. The locale type is a template parameter to | |
1102 avoid the expensive <code class="docutils literal notranslate"><span class="pre"><locale></span></code> include.</p> | |
1103 <dl class="cpp function"> | |
1104 <dt id="_CPPv4I0DpEN3fmt6formatENSt6stringERK6Locale13format_stringIDp1TEDpRR1T"> | |
1105 <span id="_CPPv3I0DpEN3fmt6formatERK6Locale13format_stringIDp1TEDpRR1T"></span><span id="_CPPv2I0DpEN3fmt6formatERK6Locale13format_stringIDp1TEDpRR1T"></span>template<typename <code class="sig-name descname">Locale</code>, typename ...<code class="sig-name descname">T</code>><br /><span class="target" id="format_8h_1ab14dd1acbc55791fb7c9c072a7280348"></span>auto <code class="sig-prename descclassname"><a class="reference internal" href="#_CPPv4I0DpEN3fmt6formatENSt6stringERK6Locale13format_stringIDp1TEDpRR1T" title="fmt::format::fmt">fmt</a><code class="sig-prename descclassname">::</code></code><code class="sig-name descname">format</code><span class="sig-paren">(</span><em class="property">const</em> <a class="reference internal" href="#_CPPv4I0DpEN3fmt6formatENSt6stringERK6Locale13format_stringIDp1TEDpRR1T" title="fmt::format::Locale">Locale</a> &<em>loc</em>, <a class="reference internal" href="#_CPPv4IDpEN3fmt13format_stringE" title="fmt::format_string">format_string</a><<a class="reference internal" href="#_CPPv4I0DpEN3fmt6formatENSt6stringERK6Locale13format_stringIDp1TEDpRR1T" title="fmt::format::T">T</a>...> <em>fmt</em>, <a class="reference internal" href="#_CPPv4I0DpEN3fmt6formatENSt6stringERK6Locale13format_stringIDp1TEDpRR1T" title="fmt::format::T">T</a>&&... <em>args</em><span class="sig-paren">)</span> -> std::string<a class="headerlink" href="#_CPPv4I0DpEN3fmt6formatENSt6stringERK6Locale13format_stringIDp1TEDpRR1T" title="Permalink to this definition">¶</a><br /></dt> | |
1106 <dd></dd></dl> | |
1107 | |
1108 <dl class="cpp function"> | |
1109 <dt id="_CPPv4I00DpEN3fmt9format_toE8OutputIt8OutputItRK6Locale13format_stringIDp1TEDpRR1T"> | |
1110 <span id="_CPPv3I00DpEN3fmt9format_toE8OutputItRK6Locale13format_stringIDp1TEDpRR1T"></span><span id="_CPPv2I00DpEN3fmt9format_toE8OutputItRK6Locale13format_stringIDp1TEDpRR1T"></span>template<typename <code class="sig-name descname">OutputIt</code>, typename <code class="sig-name descname">Locale</code>, typename ...<code class="sig-name descname">T</code>><br /><span class="target" id="format_8h_1a789034b65987d8a507e00538cab50d7a"></span>auto <code class="sig-prename descclassname"><a class="reference internal" href="#_CPPv4I00DpEN3fmt9format_toE8OutputIt8OutputItRK6Locale13format_stringIDp1TEDpRR1T" title="fmt::format_to::fmt">fmt</a><code class="sig-prename descclassname">::</code></code><code class="sig-name descname">format_to</code><span class="sig-paren">(</span><a class="reference internal" href="#_CPPv4I00DpEN3fmt9format_toE8OutputIt8OutputItRK6Locale13format_stringIDp1TEDpRR1T" title="fmt::format_to::OutputIt">OutputIt</a> <em>out</em>, <em class="property">const</em> <a class="reference internal" href="#_CPPv4I00DpEN3fmt9format_toE8OutputIt8OutputItRK6Locale13format_stringIDp1TEDpRR1T" title="fmt::format_to::Locale">Locale</a> &<em>loc</em>, <a class="reference internal" href="#_CPPv4IDpEN3fmt13format_stringE" title="fmt::format_string">format_string</a><<a class="reference internal" href="#_CPPv4I00DpEN3fmt9format_toE8OutputIt8OutputItRK6Locale13format_stringIDp1TEDpRR1T" title="fmt::format_to::T">T</a>...> <em>fmt</em>, <a class="reference internal" href="#_CPPv4I00DpEN3fmt9format_toE8OutputIt8OutputItRK6Locale13format_stringIDp1TEDpRR1T" title="fmt::format_to::T">T</a>&&... <em>args</em><span class="sig-paren">)</span> -> <a class="reference internal" href="#_CPPv4I00DpEN3fmt9format_toE8OutputIt8OutputItRK6Locale13format_stringIDp1TEDpRR1T" title="fmt::format_to::OutputIt">OutputIt</a><a class="headerlink" href="#_CPPv4I00DpEN3fmt9format_toE8OutputIt8OutputItRK6Locale13format_stringIDp1TEDpRR1T" title="Permalink to this definition">¶</a><br /></dt> | |
1111 <dd></dd></dl> | |
1112 | |
1113 <dl class="cpp function"> | |
1114 <dt id="_CPPv4I0DpEN3fmt14formatted_sizeE6size_tRK6Locale13format_stringIDp1TEDpRR1T"> | |
1115 <span id="_CPPv3I0DpEN3fmt14formatted_sizeERK6Locale13format_stringIDp1TEDpRR1T"></span><span id="_CPPv2I0DpEN3fmt14formatted_sizeERK6Locale13format_stringIDp1TEDpRR1T"></span>template<typename <code class="sig-name descname">Locale</code>, typename ...<code class="sig-name descname">T</code>><br /><span class="target" id="format_8h_1a736542f7b3651a668bc113a74e28f1c6"></span>auto <code class="sig-prename descclassname"><a class="reference internal" href="#_CPPv4I0DpEN3fmt14formatted_sizeE6size_tRK6Locale13format_stringIDp1TEDpRR1T" title="fmt::formatted_size::fmt">fmt</a><code class="sig-prename descclassname">::</code></code><code class="sig-name descname">formatted_size</code><span class="sig-paren">(</span><em class="property">const</em> <a class="reference internal" href="#_CPPv4I0DpEN3fmt14formatted_sizeE6size_tRK6Locale13format_stringIDp1TEDpRR1T" title="fmt::formatted_size::Locale">Locale</a> &<em>loc</em>, <a class="reference internal" href="#_CPPv4IDpEN3fmt13format_stringE" title="fmt::format_string">format_string</a><<a class="reference internal" href="#_CPPv4I0DpEN3fmt14formatted_sizeE6size_tRK6Locale13format_stringIDp1TEDpRR1T" title="fmt::formatted_size::T">T</a>...> <em>fmt</em>, <a class="reference internal" href="#_CPPv4I0DpEN3fmt14formatted_sizeE6size_tRK6Locale13format_stringIDp1TEDpRR1T" title="fmt::formatted_size::T">T</a>&&... <em>args</em><span class="sig-paren">)</span> -> size_t<a class="headerlink" href="#_CPPv4I0DpEN3fmt14formatted_sizeE6size_tRK6Locale13format_stringIDp1TEDpRR1T" title="Permalink to this definition">¶</a><br /></dt> | |
1116 <dd></dd></dl> | |
1117 | |
1118 </section> | |
1119 <section id="legacy-compile-time-format-string-checks"> | |
1120 <span id="legacy-checks"></span><h3>Legacy Compile-Time Format String Checks<a class="headerlink" href="#legacy-compile-time-format-string-checks" title="Permalink to this headline">¶</a></h3> | |
1121 <p><code class="docutils literal notranslate"><span class="pre">FMT_STRING</span></code> enables compile-time checks on older compilers. It requires C++14 | |
1122 or later and is a no-op in C++11.</p> | |
1123 <dl class="cpp macro"> | |
1124 <dt id="c.FMT_STRING"> | |
1125 <span class="target" id="format_8h_1a09119ad072f708d17b88704fa898aff0"></span><code class="sig-name descname">FMT_STRING</code><span class="sig-paren">(</span><em>s</em><span class="sig-paren">)</span><a class="headerlink" href="#c.FMT_STRING" title="Permalink to this definition">¶</a><br /></dt> | |
1126 <dd><p><p><p>Constructs a compile-time format string from a string literal <em>s</em>.</p> | |
1127 <p><strong>Example</strong>:</p> | |
1128 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="c1">// A compile-time error because 'd' is an invalid specifier for strings.</span> | |
1129 <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="n">FMT_STRING</span><span class="p">(</span><span class="s">"{:d}"</span><span class="p">),</span><span class="w"> </span><span class="s">"foo"</span><span class="p">);</span> | |
1130 </pre></div> | |
1131 </div> | |
1132 </p> | |
1133 </p> | |
1134 </dd></dl> | |
1135 | |
1136 <p>To force the use of legacy compile-time checks, define the preprocessor variable | |
1137 <code class="docutils literal notranslate"><span class="pre">FMT_ENFORCE_COMPILE_STRING</span></code>. When set, functions accepting <code class="docutils literal notranslate"><span class="pre">FMT_STRING</span></code> | |
1138 will fail to compile with regular strings.</p> | |
1139 </section> | |
1140 </section> | |
1141 <section id="range-and-tuple-formatting"> | |
1142 <span id="ranges-api"></span><h2>Range and Tuple Formatting<a class="headerlink" href="#range-and-tuple-formatting" title="Permalink to this headline">¶</a></h2> | |
1143 <p>The library also supports convenient formatting of ranges and tuples:</p> | |
1144 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf"><fmt/ranges.h></span> | |
1145 | |
1146 <span class="n">std</span><span class="o">::</span><span class="n">tuple</span><span class="o"><</span><span class="kt">char</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="p">,</span><span class="w"> </span><span class="kt">float</span><span class="o">></span><span class="w"> </span><span class="n">t</span><span class="p">{</span><span class="sc">'a'</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mf">2.0f</span><span class="p">};</span> | |
1147 <span class="c1">// Prints "('a', 1, 2.0)"</span> | |
1148 <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">t</span><span class="p">);</span> | |
1149 </pre></div> | |
1150 </div> | |
1151 <p>NOTE: currently, the overload of <code class="docutils literal notranslate"><span class="pre">fmt::join</span></code> for iterables exists in the main | |
1152 <code class="docutils literal notranslate"><span class="pre">format.h</span></code> header, but expect this to change in the future.</p> | |
1153 <p>Using <code class="docutils literal notranslate"><span class="pre">fmt::join</span></code>, you can separate tuple elements with a custom separator:</p> | |
1154 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf"><fmt/ranges.h></span> | |
1155 | |
1156 <span class="n">std</span><span class="o">::</span><span class="n">tuple</span><span class="o"><</span><span class="kt">int</span><span class="p">,</span><span class="w"> </span><span class="kt">char</span><span class="o">></span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="sc">'a'</span><span class="p">};</span> | |
1157 <span class="c1">// Prints "1, a"</span> | |
1158 <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">fmt</span><span class="o">::</span><span class="n">join</span><span class="p">(</span><span class="n">t</span><span class="p">,</span><span class="w"> </span><span class="s">", "</span><span class="p">));</span> | |
1159 </pre></div> | |
1160 </div> | |
1161 </section> | |
1162 <section id="date-and-time-formatting"> | |
1163 <span id="chrono-api"></span><h2>Date and Time Formatting<a class="headerlink" href="#date-and-time-formatting" title="Permalink to this headline">¶</a></h2> | |
1164 <p><code class="docutils literal notranslate"><span class="pre">fmt/chrono.h</span></code> provides formatters for</p> | |
1165 <ul class="simple"> | |
1166 <li><p><a class="reference external" href="https://en.cppreference.com/w/cpp/chrono/duration">std::chrono::duration</a></p></li> | |
1167 <li><p><a class="reference external" href="https://en.cppreference.com/w/cpp/chrono/time_point">std::chrono::time_point</a></p></li> | |
1168 <li><p><a class="reference external" href="https://en.cppreference.com/w/cpp/chrono/c/tm">std::tm</a></p></li> | |
1169 </ul> | |
1170 <p>The format syntax is described in <a class="reference internal" href="syntax.html#chrono-specs"><span class="std std-ref">Chrono Format Specifications</span></a>.</p> | |
1171 <p><strong>Example</strong>:</p> | |
1172 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf"><fmt/chrono.h></span> | |
1173 | |
1174 <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> | |
1175 <span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="kt">time_t</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">time</span><span class="p">(</span><span class="k">nullptr</span><span class="p">);</span> | |
1176 | |
1177 <span class="w"> </span><span class="c1">// Prints "The date is 2020-11-07." (with the current date):</span> | |
1178 <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 date is {:%Y-%m-%d}."</span><span class="p">,</span><span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">localtime</span><span class="p">(</span><span class="n">t</span><span class="p">));</span> | |
1179 | |
1180 <span class="w"> </span><span class="k">using</span><span class="w"> </span><span class="k">namespace</span><span class="w"> </span><span class="nn">std</span><span class="o">::</span><span class="nn">literals</span><span class="o">::</span><span class="nn">chrono_literals</span><span class="p">;</span> | |
1181 | |
1182 <span class="w"> </span><span class="c1">// Prints "Default format: 42s 100ms":</span> | |
1183 <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">"Default format: {} {}</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="w"> </span><span class="mi">42</span><span class="n">s</span><span class="p">,</span><span class="w"> </span><span class="mi">100</span><span class="n">ms</span><span class="p">);</span> | |
1184 | |
1185 <span class="w"> </span><span class="c1">// Prints "strftime-like format: 03:15:30":</span> | |
1186 <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">"strftime-like format: {:%H:%M:%S}</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="n">h</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">15</span><span class="n">min</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">30</span><span class="n">s</span><span class="p">);</span> | |
1187 <span class="p">}</span> | |
1188 </pre></div> | |
1189 </div> | |
1190 <dl class="cpp function"> | |
1191 <dt id="_CPPv4N3fmt9localtimeENSt6time_tE"> | |
1192 <span id="_CPPv3N3fmt9localtimeENSt6time_tE"></span><span id="_CPPv2N3fmt9localtimeENSt6time_tE"></span><span id="fmt::localtime__std::time_t"></span><span class="target" id="chrono_8h_1a643b7f36289ce0547f217d387f47bbf3"></span>auto <code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">localtime</code><span class="sig-paren">(</span>std::time_t <em>time</em><span class="sig-paren">)</span> -> std::tm<a class="headerlink" href="#_CPPv4N3fmt9localtimeENSt6time_tE" title="Permalink to this definition">¶</a><br /></dt> | |
1193 <dd><p>Converts given time since epoch as <code class="docutils literal notranslate"><span class="pre">std::time_t</span></code> value into calendar time, expressed in local time. </p> | |
1194 <p>Unlike <code class="docutils literal notranslate"><span class="pre">std::localtime</span></code>, this function is thread-safe on most platforms. </p> | |
1195 </dd></dl> | |
1196 | |
1197 <div class="admonition warning"> | |
1198 <p class="admonition-title">Warning</p> | |
1199 <p>doxygenfunction: Unable to resolve multiple matches for function “gmtime” with arguments ((std::time_t)) in doxygen xml output for project “format” from directory: /Users/viz/work/fmt/support/build/fmt/doc/doxyxml. | |
1200 Potential matches: | |
1201 </p> | |
1202 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="o">-</span><span class="w"> </span><span class="k">auto</span><span class="w"> </span><span class="n">gmtime</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="kt">time_t</span><span class="w"> </span><span class="n">time</span><span class="p">)</span><span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">tm</span> | |
1203 <span class="o">-</span><span class="w"> </span><span class="k">template</span><span class="o"><</span><span class="k">typename</span><span class="w"> </span><span class="nc">Duration</span><span class="o">></span><span class="w"> </span><span class="k">auto</span><span class="w"> </span><span class="n">gmtime</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">chrono</span><span class="o">::</span><span class="n">time_point</span><span class="o"><</span><span class="n">std</span><span class="o">::</span><span class="n">chrono</span><span class="o">::</span><span class="n">system_clock</span><span class="p">,</span><span class="w"> </span><span class="n">Duration</span><span class="o">></span><span class="w"> </span><span class="n">time_point</span><span class="p">)</span><span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">tm</span> | |
1204 </pre></div> | |
1205 </div> | |
1206 </div> | |
1207 </section> | |
1208 <section id="standard-library-types-formatting"> | |
1209 <span id="std-api"></span><h2>Standard Library Types Formatting<a class="headerlink" href="#standard-library-types-formatting" title="Permalink to this headline">¶</a></h2> | |
1210 <p><code class="docutils literal notranslate"><span class="pre">fmt/std.h</span></code> provides formatters for:</p> | |
1211 <ul class="simple"> | |
1212 <li><p><a class="reference external" href="https://en.cppreference.com/w/cpp/filesystem/path">std::filesystem::path</a></p></li> | |
1213 <li><p><a class="reference external" href="https://en.cppreference.com/w/cpp/thread/thread/id">std::thread::id</a></p></li> | |
1214 <li><p><a class="reference external" href="https://en.cppreference.com/w/cpp/utility/variant/monostate">std::monostate</a></p></li> | |
1215 <li><p><a class="reference external" href="https://en.cppreference.com/w/cpp/utility/variant/variant">std::variant</a></p></li> | |
1216 <li><p><a class="reference external" href="https://en.cppreference.com/w/cpp/utility/optional">std::optional</a></p></li> | |
1217 </ul> | |
1218 <section id="formatting-variants"> | |
1219 <h3>Formatting Variants<a class="headerlink" href="#formatting-variants" title="Permalink to this headline">¶</a></h3> | |
1220 <p>A <code class="docutils literal notranslate"><span class="pre">std::variant</span></code> is only formattable if every variant alternative is formattable, and requires the | |
1221 <code class="docutils literal notranslate"><span class="pre">__cpp_lib_variant</span></code> <a class="reference external" href="https://en.cppreference.com/w/cpp/feature_test">library feature</a>.</p> | |
1222 <p><strong>Example</strong>:</p> | |
1223 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf"><fmt/std.h></span> | |
1224 | |
1225 <span class="n">std</span><span class="o">::</span><span class="n">variant</span><span class="o"><</span><span class="kt">char</span><span class="p">,</span><span class="w"> </span><span class="kt">float</span><span class="o">></span><span class="w"> </span><span class="n">v0</span><span class="p">{</span><span class="sc">'x'</span><span class="p">};</span> | |
1226 <span class="c1">// Prints "variant('x')"</span> | |
1227 <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">v0</span><span class="p">);</span> | |
1228 | |
1229 <span class="n">std</span><span class="o">::</span><span class="n">variant</span><span class="o"><</span><span class="n">std</span><span class="o">::</span><span class="n">monostate</span><span class="p">,</span><span class="w"> </span><span class="kt">char</span><span class="o">></span><span class="w"> </span><span class="n">v1</span><span class="p">;</span> | |
1230 <span class="c1">// Prints "variant(monostate)"</span> | |
1231 </pre></div> | |
1232 </div> | |
1233 </section> | |
1234 </section> | |
1235 <section id="format-string-compilation"> | |
1236 <span id="compile-api"></span><h2>Format String Compilation<a class="headerlink" href="#format-string-compilation" title="Permalink to this headline">¶</a></h2> | |
1237 <p><code class="docutils literal notranslate"><span class="pre">fmt/compile.h</span></code> provides format string compilation enabled via the | |
1238 <code class="docutils literal notranslate"><span class="pre">FMT_COMPILE</span></code> macro or the <code class="docutils literal notranslate"><span class="pre">_cf</span></code> user-defined literal. Format strings | |
1239 marked with <code class="docutils literal notranslate"><span class="pre">FMT_COMPILE</span></code> or <code class="docutils literal notranslate"><span class="pre">_cf</span></code> are parsed, checked and converted into | |
1240 efficient formatting code at compile-time. This supports arguments of built-in | |
1241 and string types as well as user-defined types with <code class="docutils literal notranslate"><span class="pre">format</span></code> functions taking | |
1242 the format context type as a template parameter in their <code class="docutils literal notranslate"><span class="pre">formatter</span></code> | |
1243 specializations. For example:</p> | |
1244 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="k">template</span><span class="w"> </span><span class="o"><></span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">fmt</span><span class="o">::</span><span class="n">formatter</span><span class="o"><</span><span class="n">point</span><span class="o">></span><span class="w"> </span><span class="p">{</span> | |
1245 <span class="w"> </span><span class="k">constexpr</span><span class="w"> </span><span class="k">auto</span><span class="w"> </span><span class="n">parse</span><span class="p">(</span><span class="n">format_parse_context</span><span class="o">&</span><span class="w"> </span><span class="n">ctx</span><span class="p">);</span> | |
1246 | |
1247 <span class="w"> </span><span class="k">template</span><span class="w"> </span><span class="o"><</span><span class="k">typename</span><span class="w"> </span><span class="nc">FormatContext</span><span class="o">></span> | |
1248 <span class="w"> </span><span class="k">auto</span><span class="w"> </span><span class="n">format</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="n">point</span><span class="o">&</span><span class="w"> </span><span class="n">p</span><span class="p">,</span><span class="w"> </span><span class="n">FormatContext</span><span class="o">&</span><span class="w"> </span><span class="n">ctx</span><span class="p">)</span><span class="w"> </span><span class="k">const</span><span class="p">;</span> | |
1249 <span class="p">};</span> | |
1250 </pre></div> | |
1251 </div> | |
1252 <p>Format string compilation can generate more binary code compared to the default | |
1253 API and is only recommended in places where formatting is a performance | |
1254 bottleneck.</p> | |
1255 <dl class="cpp macro"> | |
1256 <dt id="c.FMT_COMPILE"> | |
1257 <span class="target" id="compile_8h_1a7186ba53487a4df4602ae1d75658db29"></span><code class="sig-name descname">FMT_COMPILE</code><span class="sig-paren">(</span><em>s</em><span class="sig-paren">)</span><a class="headerlink" href="#c.FMT_COMPILE" title="Permalink to this definition">¶</a><br /></dt> | |
1258 <dd><p><p><p>Converts a string literal <em>s</em> into a format string that will be parsed at | |
1259 compile time and converted into efficient formatting code. Requires C++17 | |
1260 <code class="docutils literal notranslate"><span class="pre">constexpr</span> <span class="pre">if</span></code> compiler support.</p> | |
1261 <p><strong>Example</strong>:</p> | |
1262 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="c1">// Converts 42 into std::string using the most efficient method and no</span> | |
1263 <span class="c1">// runtime format string processing.</span> | |
1264 <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="n">FMT_COMPILE</span><span class="p">(</span><span class="s">"{}"</span><span class="p">),</span><span class="w"> </span><span class="mi">42</span><span class="p">);</span> | |
1265 </pre></div> | |
1266 </div> | |
1267 </p> | |
1268 </p> | |
1269 </dd></dl> | |
1270 | |
1271 <dl class="cpp function"> | |
1272 <dt id="_CPPv4I_N15detail_exported12fixed_stringEEN3fmtli3_cfEDav"> | |
1273 <span id="_CPPv3I_N15detail_exported12fixed_stringEEN3fmtli3_cfEv"></span><span id="_CPPv2I_N15detail_exported12fixed_stringEEN3fmtli3_cfEv"></span>template<detail_exported::fixed_string <code class="sig-name descname">Str</code>><br /><span class="target" id="compile_8h_1a79b71ea3d1d76cb384707cf16136fad5"></span><em class="property">constexpr</em> auto <code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">operator""_cf</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4I_N15detail_exported12fixed_stringEEN3fmtli3_cfEDav" title="Permalink to this definition">¶</a><br /></dt> | |
1274 <dd></dd></dl> | |
1275 | |
1276 </section> | |
1277 <section id="terminal-color-and-text-style"> | |
1278 <span id="color-api"></span><h2>Terminal Color and Text Style<a class="headerlink" href="#terminal-color-and-text-style" title="Permalink to this headline">¶</a></h2> | |
1279 <p><code class="docutils literal notranslate"><span class="pre">fmt/color.h</span></code> provides support for terminal color and text style output.</p> | |
1280 <dl class="cpp function"> | |
1281 <dt id="_CPPv4I0DpEN3fmt5printEvRK10text_styleRK1SDpRK4Args"> | |
1282 <span id="_CPPv3I0DpEN3fmt5printERK10text_styleRK1SDpRK4Args"></span><span id="_CPPv2I0DpEN3fmt5printERK10text_styleRK1SDpRK4Args"></span>template<typename <code class="sig-name descname">S</code>, typename ...<code class="sig-name descname">Args</code>><br /><span class="target" id="color_8h_1a2cc2ce51809b329a491730a7b7c13318"></span>void <code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">print</code><span class="sig-paren">(</span><em class="property">const</em> text_style &<em>ts</em>, <em class="property">const</em> <a class="reference internal" href="#_CPPv4I0DpEN3fmt5printEvRK10text_styleRK1SDpRK4Args" title="fmt::print::S">S</a> &<em>format_str</em>, <em class="property">const</em> <a class="reference internal" href="#_CPPv4I0DpEN3fmt5printEvRK10text_styleRK1SDpRK4Args" title="fmt::print::Args">Args</a>&... <em>args</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4I0DpEN3fmt5printEvRK10text_styleRK1SDpRK4Args" title="Permalink to this definition">¶</a><br /></dt> | |
1283 <dd><p><p><p>Formats a string and prints it to stdout using ANSI escape sequences to | |
1284 specify text formatting.</p> | |
1285 <p><strong>Example</strong>:</p> | |
1286 <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">fmt</span><span class="o">::</span><span class="n">emphasis</span><span class="o">::</span><span class="n">bold</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">fg</span><span class="p">(</span><span class="n">fmt</span><span class="o">::</span><span class="n">color</span><span class="o">::</span><span class="n">red</span><span class="p">),</span> | |
1287 <span class="w"> </span><span class="s">"Elapsed time: {0:.2f} seconds"</span><span class="p">,</span><span class="w"> </span><span class="mf">1.23</span><span class="p">);</span> | |
1288 </pre></div> | |
1289 </div> | |
1290 </p> | |
1291 </p> | |
1292 </dd></dl> | |
1293 | |
1294 <dl class="cpp function"> | |
1295 <dt id="_CPPv4N3fmt2fgEN6detail10color_typeE"> | |
1296 <span id="_CPPv3N3fmt2fgEN6detail10color_typeE"></span><span id="_CPPv2N3fmt2fgEN6detail10color_typeE"></span><span id="fmt::fg__detail::color_type"></span><span class="target" id="color_8h_1aa0997aeb59a9ecd0592c556d36359d8f"></span>auto <code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">fg</code><span class="sig-paren">(</span>detail::color_type <em>foreground</em><span class="sig-paren">)</span> <em class="property">noexcept</em> -> text_style<a class="headerlink" href="#_CPPv4N3fmt2fgEN6detail10color_typeE" title="Permalink to this definition">¶</a><br /></dt> | |
1297 <dd><p>Creates a text style from the foreground (text) color. </p> | |
1298 </dd></dl> | |
1299 | |
1300 <dl class="cpp function"> | |
1301 <dt id="_CPPv4N3fmt2bgEN6detail10color_typeE"> | |
1302 <span id="_CPPv3N3fmt2bgEN6detail10color_typeE"></span><span id="_CPPv2N3fmt2bgEN6detail10color_typeE"></span><span id="fmt::bg__detail::color_type"></span><span class="target" id="color_8h_1a0878ee99fc1b522a83a6bf983fafb25c"></span>auto <code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">bg</code><span class="sig-paren">(</span>detail::color_type <em>background</em><span class="sig-paren">)</span> <em class="property">noexcept</em> -> text_style<a class="headerlink" href="#_CPPv4N3fmt2bgEN6detail10color_typeE" title="Permalink to this definition">¶</a><br /></dt> | |
1303 <dd><p>Creates a text style from the background color. </p> | |
1304 </dd></dl> | |
1305 | |
1306 <dl class="cpp function"> | |
1307 <dt id="_CPPv4I0EN3fmt6styledEN6detail10styled_argI14remove_cvref_tI1TEEERK1T10text_style"> | |
1308 <span id="_CPPv3I0EN3fmt6styledERK1T10text_style"></span><span id="_CPPv2I0EN3fmt6styledERK1T10text_style"></span>template<typename <code class="sig-name descname">T</code>><br /><span class="target" id="color_8h_1aaa994d7fe55bf7b40810e55b362fe107"></span>auto <code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">styled</code><span class="sig-paren">(</span><em class="property">const</em> <a class="reference internal" href="#_CPPv4I0EN3fmt6styledEN6detail10styled_argI14remove_cvref_tI1TEEERK1T10text_style" title="fmt::styled::T">T</a> &<em>value</em>, text_style <em>ts</em><span class="sig-paren">)</span> -> detail::styled_arg<remove_cvref_t<<a class="reference internal" href="#_CPPv4I0EN3fmt6styledEN6detail10styled_argI14remove_cvref_tI1TEEERK1T10text_style" title="fmt::styled::T">T</a>>><a class="headerlink" href="#_CPPv4I0EN3fmt6styledEN6detail10styled_argI14remove_cvref_tI1TEEERK1T10text_style" title="Permalink to this definition">¶</a><br /></dt> | |
1309 <dd><p><p><p>Returns an argument that will be formatted using ANSI escape sequences, | |
1310 to be used in a formatting function.</p> | |
1311 <p><strong>Example</strong>:</p> | |
1312 <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">"Elapsed time: {0:.2f} seconds"</span><span class="p">,</span> | |
1313 <span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">styled</span><span class="p">(</span><span class="mf">1.23</span><span class="p">,</span><span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">fg</span><span class="p">(</span><span class="n">fmt</span><span class="o">::</span><span class="n">color</span><span class="o">::</span><span class="n">green</span><span class="p">)</span><span class="w"> </span><span class="o">|</span> | |
1314 <span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">bg</span><span class="p">(</span><span class="n">fmt</span><span class="o">::</span><span class="n">color</span><span class="o">::</span><span class="n">blue</span><span class="p">)));</span> | |
1315 </pre></div> | |
1316 </div> | |
1317 </p> | |
1318 </p> | |
1319 </dd></dl> | |
1320 | |
1321 </section> | |
1322 <section id="system-apis"> | |
1323 <span id="os-api"></span><h2>System APIs<a class="headerlink" href="#system-apis" title="Permalink to this headline">¶</a></h2> | |
1324 <dl class="cpp class"> | |
1325 <dt id="_CPPv4N3fmt7ostreamE"> | |
1326 <span id="_CPPv3N3fmt7ostreamE"></span><span id="_CPPv2N3fmt7ostreamE"></span><span id="fmt::ostream"></span><span class="target" id="classfmt_1_1ostream"></span><em class="property">class </em><code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">ostream</code><a class="headerlink" href="#_CPPv4N3fmt7ostreamE" title="Permalink to this definition">¶</a><br /></dt> | |
1327 <dd><p>A fast output stream which is not thread-safe. </p> | |
1328 <div class="breathe-sectiondef docutils container"> | |
1329 <p class="breathe-sectiondef-title rubric">Public Functions</p> | |
1330 <dl class="cpp function"> | |
1331 <dt id="_CPPv4IDpEN3fmt7ostream5printEv13format_stringIDp1TEDpRR1T"> | |
1332 <span id="_CPPv3IDpEN3fmt7ostream5printE13format_stringIDp1TEDpRR1T"></span><span id="_CPPv2IDpEN3fmt7ostream5printE13format_stringIDp1TEDpRR1T"></span>template<typename ...<code class="sig-name descname">T</code>><br /><span class="target" id="classfmt_1_1ostream_1aeffd7c3e05f5178e689dd18e648704d5"></span>void <code class="sig-name descname">print</code><span class="sig-paren">(</span><a class="reference internal" href="#_CPPv4IDpEN3fmt13format_stringE" title="fmt::format_string">format_string</a><<a class="reference internal" href="#_CPPv4IDpEN3fmt7ostream5printEv13format_stringIDp1TEDpRR1T" title="fmt::ostream::print::T">T</a>...> <em>fmt</em>, <a class="reference internal" href="#_CPPv4IDpEN3fmt7ostream5printEv13format_stringIDp1TEDpRR1T" title="fmt::ostream::print::T">T</a>&&... <em>args</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4IDpEN3fmt7ostream5printEv13format_stringIDp1TEDpRR1T" title="Permalink to this definition">¶</a><br /></dt> | |
1333 <dd><p>Formats <code class="docutils literal notranslate"><span class="pre">args</span></code> according to specifications in <code class="docutils literal notranslate"><span class="pre">fmt</span></code> and writes the output to the file. </p> | |
1334 </dd></dl> | |
1335 | |
1336 </div> | |
1337 <div class="breathe-sectiondef docutils container"> | |
1338 <p class="breathe-sectiondef-title rubric">Friends</p> | |
1339 <dl class="cpp function"> | |
1340 <dt id="_CPPv4IDpEN3fmt7ostream11output_fileE7ostream12cstring_viewDp1T"> | |
1341 <span id="_CPPv3IDpEN3fmt7ostream11output_fileE12cstring_viewDp1T"></span><span id="_CPPv2IDpEN3fmt7ostream11output_fileE12cstring_viewDp1T"></span>template<typename ...<code class="sig-name descname">T</code>><br /><span class="target" id="classfmt_1_1ostream_1a3bac45a0a6f48bd4d040e023e4f89bbc"></span>auto <code class="sig-name descname">output_file</code><span class="sig-paren">(</span>cstring_view <em>path</em>, <a class="reference internal" href="#_CPPv4IDpEN3fmt7ostream11output_fileE7ostream12cstring_viewDp1T" title="fmt::ostream::output_file::T">T</a>... <em>params</em><span class="sig-paren">)</span> -> <a class="reference internal" href="#_CPPv4N3fmt7ostreamE" title="fmt::ostream">ostream</a><a class="headerlink" href="#_CPPv4IDpEN3fmt7ostream11output_fileE7ostream12cstring_viewDp1T" title="Permalink to this definition">¶</a><br /></dt> | |
1342 <dd><p><p><p>Opens a file for writing. Supported parameters passed in <em>params</em>:</p> | |
1343 <ul class="simple"> | |
1344 <li><p><code class="docutils literal notranslate"><span class="pre"><integer></span></code>: Flags passed to <a class="reference external" href="https://pubs.opengroup.org/onlinepubs/007904875/functions/open.html">open</a> | |
1345 (<code class="docutils literal notranslate"><span class="pre">file::WRONLY</span> <span class="pre">|</span> <span class="pre">file::CREATE</span> <span class="pre">|</span> <span class="pre">file::TRUNC</span></code> by default)</p></li> | |
1346 <li><p><code class="docutils literal notranslate"><span class="pre">buffer_size=<integer></span></code>: Output buffer size</p></li> | |
1347 </ul> | |
1348 <p><strong>Example</strong>:</p> | |
1349 <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">output_file</span><span class="p">(</span><span class="s">"guide.txt"</span><span class="p">);</span> | |
1350 <span class="n">out</span><span class="p">.</span><span class="n">print</span><span class="p">(</span><span class="s">"Don't {}"</span><span class="p">,</span><span class="w"> </span><span class="s">"Panic"</span><span class="p">);</span> | |
1351 </pre></div> | |
1352 </div> | |
1353 </p> | |
1354 </p> | |
1355 </dd></dl> | |
1356 | |
1357 </div> | |
1358 </dd></dl> | |
1359 | |
1360 <dl class="cpp function"> | |
1361 <dt id="_CPPv4IDpEN3fmt13windows_errorENSt12system_errorEi11string_viewDpRK4Args"> | |
1362 <span id="_CPPv3IDpEN3fmt13windows_errorEi11string_viewDpRK4Args"></span><span id="_CPPv2IDpEN3fmt13windows_errorEi11string_viewDpRK4Args"></span>template<typename ...<code class="sig-name descname">Args</code>><br /><span class="target" id="os_8h_1a0bee0ab8ecd5254a4612f3c9145a03e2"></span>std::system_error <code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">windows_error</code><span class="sig-paren">(</span>int <em>error_code</em>, <a class="reference internal" href="#_CPPv4N3fmt11string_viewE" title="fmt::string_view">string_view</a> <em>message</em>, <em class="property">const</em> <a class="reference internal" href="#_CPPv4IDpEN3fmt13windows_errorENSt12system_errorEi11string_viewDpRK4Args" title="fmt::windows_error::Args">Args</a>&... <em>args</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4IDpEN3fmt13windows_errorENSt12system_errorEi11string_viewDpRK4Args" title="Permalink to this definition">¶</a><br /></dt> | |
1363 <dd><p><p><p>Constructs a <code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">std::system_error</span></code> object with the description | |
1364 of the form</p> | |
1365 <pre class="literal-block"><em><message></em>: <em><system-message></em></pre> | |
1366 <p>where <em><message></em> is the formatted message and <em><system-message></em> is the | |
1367 system message corresponding to the error code. | |
1368 <em>error_code</em> is a Windows error code as given by <code class="docutils literal notranslate"><span class="pre">GetLastError</span></code>. | |
1369 If <em>error_code</em> is not a valid error code such as -1, the system message | |
1370 will look like “error -1”.</p> | |
1371 <p><strong>Example</strong>:</p> | |
1372 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="c1">// This throws a system_error with the description</span> | |
1373 <span class="c1">// cannot open file 'madeup': The system cannot find the file specified.</span> | |
1374 <span class="c1">// or similar (system message may vary).</span> | |
1375 <span class="k">const</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">filename</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"madeup"</span><span class="p">;</span> | |
1376 <span class="n">LPOFSTRUCT</span><span class="w"> </span><span class="n">of</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">LPOFSTRUCT</span><span class="p">();</span> | |
1377 <span class="n">HFILE</span><span class="w"> </span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">OpenFile</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span><span class="w"> </span><span class="o">&</span><span class="n">of</span><span class="p">,</span><span class="w"> </span><span class="n">OF_READ</span><span class="p">);</span> | |
1378 <span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">HFILE_ERROR</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> | |
1379 <span class="w"> </span><span class="k">throw</span><span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">windows_error</span><span class="p">(</span><span class="n">GetLastError</span><span class="p">(),</span> | |
1380 <span class="w"> </span><span class="s">"cannot open file '{}'"</span><span class="p">,</span><span class="w"> </span><span class="n">filename</span><span class="p">);</span> | |
1381 <span class="p">}</span> | |
1382 </pre></div> | |
1383 </div> | |
1384 </p> | |
1385 </p> | |
1386 </dd></dl> | |
1387 | |
1388 </section> | |
1389 <section id="std-ostream-support"> | |
1390 <span id="ostream-api"></span><h2><code class="docutils literal notranslate"><span class="pre">std::ostream</span></code> Support<a class="headerlink" href="#std-ostream-support" title="Permalink to this headline">¶</a></h2> | |
1391 <p><code class="docutils literal notranslate"><span class="pre">fmt/ostream.h</span></code> provides <code class="docutils literal notranslate"><span class="pre">std::ostream</span></code> support including formatting of | |
1392 user-defined types that have an overloaded insertion operator (<code class="docutils literal notranslate"><span class="pre">operator<<</span></code>). | |
1393 In order to make a type formattable via <code class="docutils literal notranslate"><span class="pre">std::ostream</span></code> you should provide a | |
1394 <code class="docutils literal notranslate"><span class="pre">formatter</span></code> specialization inherited from <code class="docutils literal notranslate"><span class="pre">ostream_formatter</span></code>:</p> | |
1395 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf"><fmt/ostream.h></span> | |
1396 | |
1397 <span class="k">struct</span><span class="w"> </span><span class="nc">date</span><span class="w"> </span><span class="p">{</span> | |
1398 <span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">year</span><span class="p">,</span><span class="w"> </span><span class="n">month</span><span class="p">,</span><span class="w"> </span><span class="n">day</span><span class="p">;</span> | |
1399 | |
1400 <span class="w"> </span><span class="k">friend</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">ostream</span><span class="o">&</span><span class="w"> </span><span class="k">operator</span><span class="o"><<</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">ostream</span><span class="o">&</span><span class="w"> </span><span class="n">os</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">date</span><span class="o">&</span><span class="w"> </span><span class="n">d</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> | |
1401 <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">os</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="n">d</span><span class="p">.</span><span class="n">year</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="sc">'-'</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="n">d</span><span class="p">.</span><span class="n">month</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="sc">'-'</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="n">d</span><span class="p">.</span><span class="n">day</span><span class="p">;</span> | |
1402 <span class="w"> </span><span class="p">}</span> | |
1403 <span class="p">};</span> | |
1404 | |
1405 <span class="k">template</span><span class="w"> </span><span class="o"><></span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">fmt</span><span class="o">::</span><span class="n">formatter</span><span class="o"><</span><span class="n">date</span><span class="o">></span><span class="w"> </span><span class="o">:</span><span class="w"> </span><span class="n">ostream_formatter</span><span class="w"> </span><span class="p">{};</span> | |
1406 | |
1407 <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 date is {}"</span><span class="p">,</span><span class="w"> </span><span class="n">date</span><span class="p">{</span><span class="mi">2012</span><span class="p">,</span><span class="w"> </span><span class="mi">12</span><span class="p">,</span><span class="w"> </span><span class="mi">9</span><span class="p">});</span> | |
1408 <span class="c1">// s == "The date is 2012-12-9"</span> | |
1409 </pre></div> | |
1410 </div> | |
1411 <dl class="cpp function"> | |
1412 <dt id="_CPPv4I0EN3fmt8streamedEN6detail13streamed_viewI1TEERK1T"> | |
1413 <span id="_CPPv3I0EN3fmt8streamedERK1T"></span><span id="_CPPv2I0EN3fmt8streamedERK1T"></span>template<typename <code class="sig-name descname">T</code>><br /><span class="target" id="ostream_8h_1afc1c53e60beb681b5b03d94d906769f6"></span><em class="property">constexpr</em> auto <code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">streamed</code><span class="sig-paren">(</span><em class="property">const</em> <a class="reference internal" href="#_CPPv4I0EN3fmt8streamedEN6detail13streamed_viewI1TEERK1T" title="fmt::streamed::T">T</a> &<em>value</em><span class="sig-paren">)</span> -> detail::streamed_view<<a class="reference internal" href="#_CPPv4I0EN3fmt8streamedEN6detail13streamed_viewI1TEERK1T" title="fmt::streamed::T">T</a>><a class="headerlink" href="#_CPPv4I0EN3fmt8streamedEN6detail13streamed_viewI1TEERK1T" title="Permalink to this definition">¶</a><br /></dt> | |
1414 <dd><p><p><p>Returns a view that formats <a class="reference internal" href="#_CPPv4I0EN3fmt8streamedEN6detail13streamed_viewI1TEERK1T" title="fmt::streamed::value"><code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">value</span></code></a> via an ostream <code class="docutils literal notranslate"><span class="pre">operator<<</span></code>.</p> | |
1415 <p><strong>Example</strong>:</p> | |
1416 <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">"Current thread id: {}</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> | |
1417 <span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">streamed</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">this_thread</span><span class="o">::</span><span class="n">get_id</span><span class="p">()));</span> | |
1418 </pre></div> | |
1419 </div> | |
1420 </p> | |
1421 </p> | |
1422 </dd></dl> | |
1423 | |
1424 <dl class="cpp function"> | |
1425 <dt id="_CPPv4IDpEN3fmt5printEvRNSt7ostreamE13format_stringIDp1TEDpRR1T"> | |
1426 <span id="_CPPv3IDpEN3fmt5printERNSt7ostreamE13format_stringIDp1TEDpRR1T"></span><span id="_CPPv2IDpEN3fmt5printERNSt7ostreamE13format_stringIDp1TEDpRR1T"></span>template<typename ...<code class="sig-name descname">T</code>><br /><span class="target" id="ostream_8h_1a091104cf24873dda703cb3a3202f25f5"></span>void <code class="sig-prename descclassname"><a class="reference internal" href="#_CPPv4IDpEN3fmt5printEvRNSt7ostreamE13format_stringIDp1TEDpRR1T" title="fmt::print::fmt">fmt</a><code class="sig-prename descclassname">::</code></code><code class="sig-name descname">print</code><span class="sig-paren">(</span>std::ostream &<em>os</em>, <a class="reference internal" href="#_CPPv4IDpEN3fmt13format_stringE" title="fmt::format_string">format_string</a><<a class="reference internal" href="#_CPPv4IDpEN3fmt5printEvRNSt7ostreamE13format_stringIDp1TEDpRR1T" title="fmt::print::T">T</a>...> <em>fmt</em>, <a class="reference internal" href="#_CPPv4IDpEN3fmt5printEvRNSt7ostreamE13format_stringIDp1TEDpRR1T" title="fmt::print::T">T</a>&&... <em>args</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4IDpEN3fmt5printEvRNSt7ostreamE13format_stringIDp1TEDpRR1T" title="Permalink to this definition">¶</a><br /></dt> | |
1427 <dd><p><p><p>Prints formatted data to the stream <em>os</em>.</p> | |
1428 <p><strong>Example</strong>:</p> | |
1429 <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">cerr</span><span class="p">,</span><span class="w"> </span><span class="s">"Don't {}!"</span><span class="p">,</span><span class="w"> </span><span class="s">"panic"</span><span class="p">);</span> | |
1430 </pre></div> | |
1431 </div> | |
1432 </p> | |
1433 </p> | |
1434 </dd></dl> | |
1435 | |
1436 </section> | |
1437 <section id="printf-formatting"> | |
1438 <span id="printf-api"></span><h2><code class="docutils literal notranslate"><span class="pre">printf</span></code> Formatting<a class="headerlink" href="#printf-formatting" title="Permalink to this headline">¶</a></h2> | |
1439 <p>The header <code class="docutils literal notranslate"><span class="pre">fmt/printf.h</span></code> provides <code class="docutils literal notranslate"><span class="pre">printf</span></code>-like formatting functionality. | |
1440 The following functions use <a class="reference external" href="https://pubs.opengroup.org/onlinepubs/009695399/functions/fprintf.html">printf format string syntax</a> with | |
1441 the POSIX extension for positional arguments. Unlike their standard | |
1442 counterparts, the <code class="docutils literal notranslate"><span class="pre">fmt</span></code> functions are type-safe and throw an exception if an | |
1443 argument type doesn’t match its format specification.</p> | |
1444 <dl class="cpp function"> | |
1445 <dt id="_CPPv4IDpEN3fmt6printfEi11string_viewDpRK1T"> | |
1446 <span id="_CPPv3IDpEN3fmt6printfE11string_viewDpRK1T"></span><span id="_CPPv2IDpEN3fmt6printfE11string_viewDpRK1T"></span>template<typename ...<code class="sig-name descname">T</code>><br /><span class="target" id="printf_8h_1a40037d3bb325dbb41ffdefaa3063fc61"></span>auto <code class="sig-prename descclassname"><a class="reference internal" href="#_CPPv4IDpEN3fmt6printfEi11string_viewDpRK1T" title="fmt::printf::fmt">fmt</a><code class="sig-prename descclassname">::</code></code><code class="sig-name descname">printf</code><span class="sig-paren">(</span><a class="reference internal" href="#_CPPv4N3fmt11string_viewE" title="fmt::string_view">string_view</a> <em>fmt</em>, <em class="property">const</em> <a class="reference internal" href="#_CPPv4IDpEN3fmt6printfEi11string_viewDpRK1T" title="fmt::printf::T">T</a>&... <em>args</em><span class="sig-paren">)</span> -> int<a class="headerlink" href="#_CPPv4IDpEN3fmt6printfEi11string_viewDpRK1T" title="Permalink to this definition">¶</a><br /></dt> | |
1447 <dd><p><p><p>Prints formatted data to <code class="docutils literal notranslate"><span class="pre">stdout</span></code>.</p> | |
1448 <p><strong>Example</strong>:</p> | |
1449 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="n">fmt</span><span class="o">::</span><span class="n">printf</span><span class="p">(</span><span class="s">"Elapsed time: %.2f seconds"</span><span class="p">,</span><span class="w"> </span><span class="mf">1.23</span><span class="p">);</span> | |
1450 </pre></div> | |
1451 </div> | |
1452 </p> | |
1453 </p> | |
1454 </dd></dl> | |
1455 | |
1456 <dl class="cpp function"> | |
1457 <dt id="_CPPv4I0Dp0EN3fmt7fprintfEiPNSt4FILEERK1SDpRK1T"> | |
1458 <span id="_CPPv3I0Dp0EN3fmt7fprintfEPNSt4FILEERK1SDpRK1T"></span><span id="_CPPv2I0Dp0EN3fmt7fprintfEPNSt4FILEERK1SDpRK1T"></span>template<typename <code class="sig-name descname">S</code>, typename ...<code class="sig-name descname">T</code>, typename <code class="sig-name descname">Char</code> = char_t<<a class="reference internal" href="#_CPPv4I0Dp0EN3fmt7fprintfEiPNSt4FILEERK1SDpRK1T" title="fmt::fprintf::S">S</a>>><br /><span class="target" id="printf_8h_1a4f91e0cd05d87b5d3d3b77eee1a7d07a"></span>auto <code class="sig-prename descclassname"><a class="reference internal" href="#_CPPv4I0Dp0EN3fmt7fprintfEiPNSt4FILEERK1SDpRK1T" title="fmt::fprintf::fmt">fmt</a><code class="sig-prename descclassname">::</code></code><code class="sig-name descname">fprintf</code><span class="sig-paren">(</span>std::FILE *<em>f</em>, <em class="property">const</em> <a class="reference internal" href="#_CPPv4I0Dp0EN3fmt7fprintfEiPNSt4FILEERK1SDpRK1T" title="fmt::fprintf::S">S</a> &<em>fmt</em>, <em class="property">const</em> <a class="reference internal" href="#_CPPv4I0Dp0EN3fmt7fprintfEiPNSt4FILEERK1SDpRK1T" title="fmt::fprintf::T">T</a>&... <em>args</em><span class="sig-paren">)</span> -> int<a class="headerlink" href="#_CPPv4I0Dp0EN3fmt7fprintfEiPNSt4FILEERK1SDpRK1T" title="Permalink to this definition">¶</a><br /></dt> | |
1459 <dd><p><p><p>Prints formatted data to the file <em>f</em>.</p> | |
1460 <p><strong>Example</strong>:</p> | |
1461 <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="n">fmt</span><span class="o">::</span><span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span><span class="w"> </span><span class="s">"Don't %s!"</span><span class="p">,</span><span class="w"> </span><span class="s">"panic"</span><span class="p">);</span> | |
1462 </pre></div> | |
1463 </div> | |
1464 </p> | |
1465 </p> | |
1466 </dd></dl> | |
1467 | |
1468 <dl class="cpp function"> | |
1469 <dt id="_CPPv4I0Dp0EN3fmt7sprintfENSt12basic_stringI4CharEERK1SDpRK1T"> | |
1470 <span id="_CPPv3I0Dp0EN3fmt7sprintfERK1SDpRK1T"></span><span id="_CPPv2I0Dp0EN3fmt7sprintfERK1SDpRK1T"></span>template<typename <code class="sig-name descname">S</code>, typename ...<code class="sig-name descname">T</code>, typename <code class="sig-name descname">Char</code> = enable_if_t<detail::is_string<<a class="reference internal" href="#_CPPv4I0Dp0EN3fmt7sprintfENSt12basic_stringI4CharEERK1SDpRK1T" title="fmt::sprintf::S">S</a>>::value, char_t<<a class="reference internal" href="#_CPPv4I0Dp0EN3fmt7sprintfENSt12basic_stringI4CharEERK1SDpRK1T" title="fmt::sprintf::S">S</a>>>><br /><span class="target" id="printf_8h_1ad69b8f4ce3c9f39b062943851ce42626"></span>auto <code class="sig-prename descclassname"><a class="reference internal" href="#_CPPv4I0Dp0EN3fmt7sprintfENSt12basic_stringI4CharEERK1SDpRK1T" title="fmt::sprintf::fmt">fmt</a><code class="sig-prename descclassname">::</code></code><code class="sig-name descname">sprintf</code><span class="sig-paren">(</span><em class="property">const</em> <a class="reference internal" href="#_CPPv4I0Dp0EN3fmt7sprintfENSt12basic_stringI4CharEERK1SDpRK1T" title="fmt::sprintf::S">S</a> &<em>fmt</em>, <em class="property">const</em> <a class="reference internal" href="#_CPPv4I0Dp0EN3fmt7sprintfENSt12basic_stringI4CharEERK1SDpRK1T" title="fmt::sprintf::T">T</a>&... <em>args</em><span class="sig-paren">)</span> -> std::basic_string<<a class="reference internal" href="#_CPPv4I0Dp0EN3fmt7sprintfENSt12basic_stringI4CharEERK1SDpRK1T" title="fmt::sprintf::Char">Char</a>><a class="headerlink" href="#_CPPv4I0Dp0EN3fmt7sprintfENSt12basic_stringI4CharEERK1SDpRK1T" title="Permalink to this definition">¶</a><br /></dt> | |
1471 <dd><p><p><p>Formats arguments and returns the result as a string.</p> | |
1472 <p><strong>Example</strong>:</p> | |
1473 <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">message</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">sprintf</span><span class="p">(</span><span class="s">"The answer is %d"</span><span class="p">,</span><span class="w"> </span><span class="mi">42</span><span class="p">);</span> | |
1474 </pre></div> | |
1475 </div> | |
1476 </p> | |
1477 </p> | |
1478 </dd></dl> | |
1479 | |
1480 </section> | |
1481 <section id="wchar-t-support"> | |
1482 <span id="xchar-api"></span><h2><code class="docutils literal notranslate"><span class="pre">wchar_t</span></code> Support<a class="headerlink" href="#wchar-t-support" title="Permalink to this headline">¶</a></h2> | |
1483 <p>The optional header <code class="docutils literal notranslate"><span class="pre">fmt/xchar.h</span></code> provides support for <code class="docutils literal notranslate"><span class="pre">wchar_t</span></code> and exotic | |
1484 character types.</p> | |
1485 <dl class="cpp struct"> | |
1486 <dt id="_CPPv4I0EN3fmt7is_charE"> | |
1487 <span id="_CPPv3I0EN3fmt7is_charE"></span><span id="_CPPv2I0EN3fmt7is_charE"></span>template<typename <code class="sig-name descname">T</code>><br /><span class="target" id="structfmt_1_1is__char"></span><em class="property">struct </em><code class="sig-name descname">is_char</code> : <em class="property">public</em> std::false_type<a class="headerlink" href="#_CPPv4I0EN3fmt7is_charE" title="Permalink to this definition">¶</a><br /></dt> | |
1488 <dd><p>Specifies if <code class="docutils literal notranslate"><span class="pre">T</span></code> is a character type. </p> | |
1489 <p>Can be specialized by users. </p> | |
1490 </dd></dl> | |
1491 | |
1492 <dl class="cpp type"> | |
1493 <dt id="_CPPv4N3fmt12wstring_viewE"> | |
1494 <span id="_CPPv3N3fmt12wstring_viewE"></span><span id="_CPPv2N3fmt12wstring_viewE"></span><span class="target" id="xchar_8h_1ad05bfd634fe8a5381ae220a52eaac7ba"></span><em class="property">using </em><code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">wstring_view</code> = <a class="reference internal" href="#_CPPv4I0EN3fmt17basic_string_viewE" title="fmt::basic_string_view">basic_string_view</a><wchar_t><a class="headerlink" href="#_CPPv4N3fmt12wstring_viewE" title="Permalink to this definition">¶</a><br /></dt> | |
1495 <dd></dd></dl> | |
1496 | |
1497 <dl class="cpp type"> | |
1498 <dt id="_CPPv4N3fmt15wformat_contextE"> | |
1499 <span id="_CPPv3N3fmt15wformat_contextE"></span><span id="_CPPv2N3fmt15wformat_contextE"></span><span class="target" id="xchar_8h_1a5c1e6b5dd3579e2734c620cb1977d671"></span><em class="property">using </em><code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">wformat_context</code> = buffer_context<wchar_t><a class="headerlink" href="#_CPPv4N3fmt15wformat_contextE" title="Permalink to this definition">¶</a><br /></dt> | |
1500 <dd></dd></dl> | |
1501 | |
1502 <dl class="cpp function"> | |
1503 <dt id="_CPPv4I0EN3fmt10to_wstringENSt7wstringERK1T"> | |
1504 <span id="_CPPv3I0EN3fmt10to_wstringERK1T"></span><span id="_CPPv2I0EN3fmt10to_wstringERK1T"></span>template<typename <code class="sig-name descname">T</code>><br /><span class="target" id="xchar_8h_1a97485c79bd9998f452c6aec356f13930"></span>auto <code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">to_wstring</code><span class="sig-paren">(</span><em class="property">const</em> <a class="reference internal" href="#_CPPv4I0EN3fmt10to_wstringENSt7wstringERK1T" title="fmt::to_wstring::T">T</a> &<em>value</em><span class="sig-paren">)</span> -> std::wstring<a class="headerlink" href="#_CPPv4I0EN3fmt10to_wstringENSt7wstringERK1T" title="Permalink to this definition">¶</a><br /></dt> | |
1505 <dd><p>Converts <em>value</em> to <code class="docutils literal notranslate"><span class="pre">std::wstring</span></code> using the default format for type <em>T</em>. </p> | |
1506 </dd></dl> | |
1507 | |
1508 </section> | |
1509 <section id="compatibility-with-c-20-std-format"> | |
1510 <h2>Compatibility with C++20 <code class="docutils literal notranslate"><span class="pre">std::format</span></code><a class="headerlink" href="#compatibility-with-c-20-std-format" title="Permalink to this headline">¶</a></h2> | |
1511 <p>{fmt} implements nearly all of the <a class="reference external" href="https://en.cppreference.com/w/cpp/utility/format">C++20 formatting library</a> with the following | |
1512 differences:</p> | |
1513 <ul class="simple"> | |
1514 <li><p>Names are defined in the <code class="docutils literal notranslate"><span class="pre">fmt</span></code> namespace instead of <code class="docutils literal notranslate"><span class="pre">std</span></code> to avoid | |
1515 collisions with standard library implementations.</p></li> | |
1516 <li><p>Width calculation doesn’t use grapheme clusterization. The latter has been | |
1517 implemented in a separate branch but hasn’t been integrated yet.</p></li> | |
1518 <li><p>Most C++20 chrono types are not supported yet.</p></li> | |
1519 </ul> | |
1520 </section> | |
1521 </section> | |
1522 | |
1523 | |
1524 </div> | |
1525 </div> | |
1526 </div> | |
1527 | |
1528 | |
1529 | |
1530 <div class="footer" role="contentinfo"> | |
1531 © Copyright 2012-present, Victor Zverovich. | |
1532 Created using <a href="http://sphinx-doc.org/">Sphinx</a> 3.3.0. | |
1533 </div> | |
1534 | |
1535 <script src="_static/bootstrap.min.js"></script> | |
1536 | |
1537 </body> | |
1538 </html> |