api.html 189 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
  8. <title>API Reference &mdash; fmt 9.1.0 documentation</title>
  9. <link rel="stylesheet" href="_static/basic.css" type="text/css" />
  10. <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  11. <link rel="stylesheet" href="_static/breathe.css" type="text/css" />
  12. <script type="text/javascript">
  13. var DOCUMENTATION_OPTIONS = {
  14. URL_ROOT: './',
  15. VERSION: '9.1.0',
  16. COLLAPSE_INDEX: false,
  17. FILE_SUFFIX: '.html',
  18. LINK_SUFFIX: '.html',
  19. SOURCELINK_SUFFIX: '.txt',
  20. HAS_SOURCE: true,
  21. SOURCELINK_SUFFIX: '.txt'
  22. };
  23. </script>
  24. <script src="_static/jquery.js"></script>
  25. <script src="_static/underscore.js"></script>
  26. <script src="_static/doctools.js"></script>
  27. <script src="_static/language_data.js"></script>
  28. <link rel="index" title="Index" href="genindex.html" />
  29. <link rel="search" title="Search" href="search.html" />
  30. <meta name="description" content="Small, safe and fast formatting library">
  31. <meta name="keywords" content="C++, formatting, printf, string, library">
  32. <meta name="author" content="Victor Zverovich">
  33. <link rel="stylesheet" href="_static/fmt.css">
  34. <script async src="https://www.googletagmanager.com/gtag/js?id=UA-20116650-4"></script>
  35. <script>
  36. window.dataLayer = window.dataLayer || [];
  37. function gtag(){dataLayer.push(arguments);}
  38. gtag('js', new Date());
  39. gtag('config', 'UA-20116650-4');
  40. </script>
  41. </head>
  42. <body role="document">
  43. <nav class="navbar navbar-inverse">
  44. <div class="tb-container">
  45. <div class="row">
  46. <div class="navbar-content">
  47. <div class="navbar-header">
  48. <button type="button" class="navbar-toggle collapsed"
  49. data-toggle="collapse" data-target=".navbar-collapse">
  50. <span class="sr-only">Toggle navigation</span>
  51. <span class="icon-bar"></span>
  52. <span class="icon-bar"></span>
  53. <span class="icon-bar"></span>
  54. </button>
  55. <a class="navbar-brand" href="index.html">{fmt}</a>
  56. </div>
  57. <div class="collapse navbar-collapse">
  58. <ul class="nav navbar-nav">
  59. <li class="dropdown">
  60. <a href="#" class="dropdown-toggle" data-toggle="dropdown"
  61. role="button" aria-expanded="false">9.1.0
  62. <span class="caret"></span></a>
  63. <ul class="dropdown-menu" role="menu">
  64. <li><a href="https://fmt.dev/9.1.0">9.1.0</a></li>
  65. <li><a href="https://fmt.dev/9.0.0">9.0.0</a></li>
  66. <li><a href="https://fmt.dev/8.1.1">8.1.1</a></li>
  67. </ul>
  68. </li>
  69. <li><a href="contents.html">Contents</a></li>
  70. <li><a href="usage.html">Usage</a></li>
  71. <li class="active"><a href="api.html">API
  72. <span class="sr-only">(current)</span></a></li>
  73. <li><a href="syntax.html">Syntax</a></li>
  74. </ul>
  75. <form class="navbar-form navbar-right" role="search" action="search.html"
  76. method="get">
  77. <div class="form-group">
  78. <input type="text" name="q" class="form-control"
  79. placeholder="Search" >
  80. </div>
  81. <input type="hidden" name="check_keywords" value="yes" />
  82. <input type="hidden" name="area" value="default" />
  83. </form>
  84. </div>
  85. </div>
  86. </div>
  87. </div>
  88. </nav>
  89. <div class="tb-container">
  90. <div class="row">
  91. <div class="content">
  92. <section id="api-reference">
  93. <span id="string-formatting-api"></span><h1>API Reference<a class="headerlink" href="#api-reference" title="Permalink to this headline">¶</a></h1>
  94. <p>The {fmt} library API consists of the following parts:</p>
  95. <ul class="simple">
  96. <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
  97. 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>
  98. <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
  99. formatting functions and locale support</p></li>
  100. <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>
  101. <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>
  102. <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>
  103. <li><p><a class="reference internal" href="#compile-api"><span class="std std-ref">fmt/compile.h</span></a>: format string compilation</p></li>
  104. <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>
  105. <li><p><a class="reference internal" href="#os-api"><span class="std std-ref">fmt/os.h</span></a>: system APIs</p></li>
  106. <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>
  107. <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>
  108. <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>
  109. </ul>
  110. <p>All functions and types provided by the library reside in namespace <code class="docutils literal notranslate"><span class="pre">fmt</span></code> and
  111. macros have prefix <code class="docutils literal notranslate"><span class="pre">FMT_</span></code>.</p>
  112. <section id="core-api">
  113. <span id="id1"></span><h2>Core API<a class="headerlink" href="#core-api" title="Permalink to this headline">¶</a></h2>
  114. <p><code class="docutils literal notranslate"><span class="pre">fmt/core.h</span></code> defines the core API which provides main formatting functions
  115. for <code class="docutils literal notranslate"><span class="pre">char</span></code>/UTF-8 with C++20 compile-time checks. It has minimal include
  116. dependencies for better compile times. This header is only beneficial when
  117. using {fmt} as a library and not in the header-only mode.</p>
  118. <p>The following functions use <a class="reference internal" href="syntax.html#syntax"><span class="std std-ref">format string syntax</span></a>
  119. similar to that of Python’s <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str.format">str.format</a>.
  120. They take <em>fmt</em> and <em>args</em> as arguments.</p>
  121. <p><em>fmt</em> is a format string that contains literal text and replacement fields
  122. surrounded by braces <code class="docutils literal notranslate"><span class="pre">{}</span></code>. The fields are replaced with formatted arguments
  123. 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
  124. implicitly constructed from a string literal or a <code class="docutils literal notranslate"><span class="pre">constexpr</span></code> string and is
  125. checked at compile time in C++20. To pass a runtime format string wrap it in
  126. <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>
  127. <p><em>args</em> is an argument list representing objects to be formatted.</p>
  128. <span class="target" id="format"></span><dl class="cpp function">
  129. <dt id="_CPPv4IDpEN3fmt6formatENSt6stringE13format_stringIDp1TEDpRR1T">
  130. <span id="_CPPv3IDpEN3fmt6formatE13format_stringIDp1TEDpRR1T"></span><span id="_CPPv2IDpEN3fmt6formatE13format_stringIDp1TEDpRR1T"></span>template&lt;typename ...<code class="sig-name descname">T</code>&gt;<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>&lt;<a class="reference internal" href="#_CPPv4IDpEN3fmt6formatENSt6stringE13format_stringIDp1TEDpRR1T" title="fmt::format::T">T</a>...&gt; <em>fmt</em>, <a class="reference internal" href="#_CPPv4IDpEN3fmt6formatENSt6stringE13format_stringIDp1TEDpRR1T" title="fmt::format::T">T</a>&amp;&amp;... <em>args</em><span class="sig-paren">)</span> -&gt; std::string<a class="headerlink" href="#_CPPv4IDpEN3fmt6formatENSt6stringE13format_stringIDp1TEDpRR1T" title="Permalink to this definition">¶</a><br /></dt>
  131. <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
  132. as a string.</p>
  133. <p><strong>Example</strong>:</p>
  134. <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;fmt/core.h&gt;</span><span class="cp"></span>
  135. <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">&quot;The answer is {}.&quot;</span><span class="p">,</span><span class="w"> </span><span class="mi">42</span><span class="p">);</span><span class="w"></span>
  136. </pre></div>
  137. </div>
  138. </p>
  139. </p>
  140. </dd></dl>
  141. <dl class="cpp function">
  142. <dt id="_CPPv4N3fmt7vformatE11string_view11format_args">
  143. <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> -&gt; std::string<a class="headerlink" href="#_CPPv4N3fmt7vformatE11string_view11format_args" title="Permalink to this definition">¶</a><br /></dt>
  144. <dd></dd></dl>
  145. <dl class="cpp function">
  146. <dt id="_CPPv4I0DpEN3fmt9format_toE8OutputIt8OutputIt13format_stringIDp1TEDpRR1T">
  147. <span id="_CPPv3I0DpEN3fmt9format_toE8OutputIt13format_stringIDp1TEDpRR1T"></span><span id="_CPPv2I0DpEN3fmt9format_toE8OutputIt13format_stringIDp1TEDpRR1T"></span>template&lt;typename <code class="sig-name descname">OutputIt</code>, typename ...<code class="sig-name descname">T</code>&gt;<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>&lt;<a class="reference internal" href="#_CPPv4I0DpEN3fmt9format_toE8OutputIt8OutputIt13format_stringIDp1TEDpRR1T" title="fmt::format_to::T">T</a>...&gt; <em>fmt</em>, <a class="reference internal" href="#_CPPv4I0DpEN3fmt9format_toE8OutputIt8OutputIt13format_stringIDp1TEDpRR1T" title="fmt::format_to::T">T</a>&amp;&amp;... <em>args</em><span class="sig-paren">)</span> -&gt; <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>
  148. <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
  149. the output iterator <code class="docutils literal notranslate"><span class="pre">out</span></code> and returns the iterator past the end of the output
  150. 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>
  151. <p><strong>Example</strong>:</p>
  152. <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">&lt;</span><span class="kt">char</span><span class="o">&gt;</span><span class="p">();</span><span class="w"></span>
  153. <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">&quot;{}&quot;</span><span class="p">,</span><span class="w"> </span><span class="mi">42</span><span class="p">);</span><span class="w"></span>
  154. </pre></div>
  155. </div>
  156. </p>
  157. </p>
  158. </dd></dl>
  159. <dl class="cpp function">
  160. <dt id="_CPPv4I0DpEN3fmt11format_to_nE18format_to_n_resultI8OutputItE8OutputIt6size_t13format_stringIDp1TEDpRR1T">
  161. <span id="_CPPv3I0DpEN3fmt11format_to_nE8OutputIt6size_t13format_stringIDp1TEDpRR1T"></span><span id="_CPPv2I0DpEN3fmt11format_to_nE8OutputIt6size_t13format_stringIDp1TEDpRR1T"></span>template&lt;typename <code class="sig-name descname">OutputIt</code>, typename ...<code class="sig-name descname">T</code>&gt;<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>&lt;<a class="reference internal" href="#_CPPv4I0DpEN3fmt11format_to_nE18format_to_n_resultI8OutputItE8OutputIt6size_t13format_stringIDp1TEDpRR1T" title="fmt::format_to_n::T">T</a>...&gt; <em>fmt</em>, <a class="reference internal" href="#_CPPv4I0DpEN3fmt11format_to_nE18format_to_n_resultI8OutputItE8OutputIt6size_t13format_stringIDp1TEDpRR1T" title="fmt::format_to_n::T">T</a>&amp;&amp;... <em>args</em><span class="sig-paren">)</span> -&gt; <a class="reference internal" href="#_CPPv4I0EN3fmt18format_to_n_resultE" title="fmt::format_to_n_result">format_to_n_result</a>&lt;<a class="reference internal" href="#_CPPv4I0DpEN3fmt11format_to_nE18format_to_n_resultI8OutputItE8OutputIt6size_t13format_stringIDp1TEDpRR1T" title="fmt::format_to_n::OutputIt">OutputIt</a>&gt;<a class="headerlink" href="#_CPPv4I0DpEN3fmt11format_to_nE18format_to_n_resultI8OutputItE8OutputIt6size_t13format_stringIDp1TEDpRR1T" title="Permalink to this definition">¶</a><br /></dt>
  162. <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>
  163. characters of the result to the output iterator <code class="docutils literal notranslate"><span class="pre">out</span></code> and returns the total
  164. (not truncated) output size and the iterator past the end of the output range.
  165. <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>
  166. </p>
  167. </p>
  168. </dd></dl>
  169. <dl class="cpp function">
  170. <dt id="_CPPv4IDpEN3fmt14formatted_sizeE6size_t13format_stringIDp1TEDpRR1T">
  171. <span id="_CPPv3IDpEN3fmt14formatted_sizeE13format_stringIDp1TEDpRR1T"></span><span id="_CPPv2IDpEN3fmt14formatted_sizeE13format_stringIDp1TEDpRR1T"></span>template&lt;typename ...<code class="sig-name descname">T</code>&gt;<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>&lt;<a class="reference internal" href="#_CPPv4IDpEN3fmt14formatted_sizeE6size_t13format_stringIDp1TEDpRR1T" title="fmt::formatted_size::T">T</a>...&gt; <em>fmt</em>, <a class="reference internal" href="#_CPPv4IDpEN3fmt14formatted_sizeE6size_t13format_stringIDp1TEDpRR1T" title="fmt::formatted_size::T">T</a>&amp;&amp;... <em>args</em><span class="sig-paren">)</span> -&gt; size_t<a class="headerlink" href="#_CPPv4IDpEN3fmt14formatted_sizeE6size_t13format_stringIDp1TEDpRR1T" title="Permalink to this definition">¶</a><br /></dt>
  172. <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>
  173. </dd></dl>
  174. <dl class="cpp struct">
  175. <dt id="_CPPv4I0EN3fmt18format_to_n_resultE">
  176. <span id="_CPPv3I0EN3fmt18format_to_n_resultE"></span><span id="_CPPv2I0EN3fmt18format_to_n_resultE"></span>template&lt;typename <code class="sig-name descname">OutputIt</code>&gt;<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>
  177. <dd><div class="breathe-sectiondef docutils container">
  178. <p class="breathe-sectiondef-title rubric">Public Members</p>
  179. <dl class="cpp var">
  180. <dt id="_CPPv4N3fmt18format_to_n_result3outE">
  181. <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>
  182. <dd><p>Iterator past the end of the output range. </p>
  183. </dd></dl>
  184. <dl class="cpp var">
  185. <dt id="_CPPv4N3fmt18format_to_n_result4sizeE">
  186. <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>
  187. <dd><p>Total (not truncated) output size. </p>
  188. </dd></dl>
  189. </div>
  190. </dd></dl>
  191. <span class="target" id="print"></span><dl class="cpp function">
  192. <dt id="_CPPv4IDpEN3fmt5printEv13format_stringIDp1TEDpRR1T">
  193. <span id="_CPPv3IDpEN3fmt5printE13format_stringIDp1TEDpRR1T"></span><span id="_CPPv2IDpEN3fmt5printE13format_stringIDp1TEDpRR1T"></span>template&lt;typename ...<code class="sig-name descname">T</code>&gt;<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>&lt;<a class="reference internal" href="#_CPPv4IDpEN3fmt5printEv13format_stringIDp1TEDpRR1T" title="fmt::print::T">T</a>...&gt; <em>fmt</em>, <a class="reference internal" href="#_CPPv4IDpEN3fmt5printEv13format_stringIDp1TEDpRR1T" title="fmt::print::T">T</a>&amp;&amp;... <em>args</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4IDpEN3fmt5printEv13format_stringIDp1TEDpRR1T" title="Permalink to this definition">¶</a><br /></dt>
  194. <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
  195. to <code class="docutils literal notranslate"><span class="pre">stdout</span></code>.</p>
  196. <p><strong>Example</strong>:</p>
  197. <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">&quot;Elapsed time: {0:.2f} seconds&quot;</span><span class="p">,</span><span class="w"> </span><span class="mf">1.23</span><span class="p">);</span><span class="w"></span>
  198. </pre></div>
  199. </div>
  200. </p>
  201. </p>
  202. </dd></dl>
  203. <dl class="cpp function">
  204. <dt id="_CPPv4N3fmt6vprintE11string_view11format_args">
  205. <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>
  206. <dd></dd></dl>
  207. <dl class="cpp function">
  208. <dt id="_CPPv4IDpEN3fmt5printEvPNSt4FILEE13format_stringIDp1TEDpRR1T">
  209. <span id="_CPPv3IDpEN3fmt5printEPNSt4FILEE13format_stringIDp1TEDpRR1T"></span><span id="_CPPv2IDpEN3fmt5printEPNSt4FILEE13format_stringIDp1TEDpRR1T"></span>template&lt;typename ...<code class="sig-name descname">T</code>&gt;<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>&lt;<a class="reference internal" href="#_CPPv4IDpEN3fmt5printEvPNSt4FILEE13format_stringIDp1TEDpRR1T" title="fmt::print::T">T</a>...&gt; <em>fmt</em>, <a class="reference internal" href="#_CPPv4IDpEN3fmt5printEvPNSt4FILEE13format_stringIDp1TEDpRR1T" title="fmt::print::T">T</a>&amp;&amp;... <em>args</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4IDpEN3fmt5printEvPNSt4FILEE13format_stringIDp1TEDpRR1T" title="Permalink to this definition">¶</a><br /></dt>
  210. <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
  211. output to the file <code class="docutils literal notranslate"><span class="pre">f</span></code>.</p>
  212. <p><strong>Example</strong>:</p>
  213. <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">&quot;Don&#39;t {}!&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;panic&quot;</span><span class="p">);</span><span class="w"></span>
  214. </pre></div>
  215. </div>
  216. </p>
  217. </p>
  218. </dd></dl>
  219. <dl class="cpp function">
  220. <dt id="_CPPv4N3fmt6vprintEPNSt4FILEE11string_view11format_args">
  221. <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>
  222. <dd></dd></dl>
  223. <section id="compile-time-format-string-checks">
  224. <h3>Compile-Time Format String Checks<a class="headerlink" href="#compile-time-format-string-checks" title="Permalink to this headline">¶</a></h3>
  225. <p>Compile-time checks are enabled by default on compilers that support C++20
  226. <code class="docutils literal notranslate"><span class="pre">consteval</span></code>. On older compilers you can use the <code class="docutils literal notranslate"><span class="pre">FMT_STRING</span></code> macro defined
  227. in <code class="docutils literal notranslate"><span class="pre">fmt/format.h</span></code> instead. It requires C++14 and is a no-op in C++11.</p>
  228. <dl class="cpp macro">
  229. <dt id="c.FMT_STRING">
  230. <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>
  231. <dd><p><p><p>Constructs a compile-time format string from a string literal <em>s</em>.</p>
  232. <p><strong>Example</strong>:</p>
  233. <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="c1">// A compile-time error because &#39;d&#39; is an invalid specifier for strings.</span>
  234. <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">&quot;{:d}&quot;</span><span class="p">),</span><span class="w"> </span><span class="s">&quot;foo&quot;</span><span class="p">);</span><span class="w"></span>
  235. </pre></div>
  236. </div>
  237. </p>
  238. </p>
  239. </dd></dl>
  240. <p>To force the use of legacy compile-time checks, define the preprocessor variable
  241. <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>
  242. will fail to compile with regular strings. Runtime-checked formatting is still
  243. possible using <code class="docutils literal notranslate"><span class="pre">fmt::vformat</span></code>, <code class="docutils literal notranslate"><span class="pre">fmt::vprint</span></code>, etc.</p>
  244. <dl class="cpp class">
  245. <dt id="_CPPv4I0DpEN3fmt19basic_format_stringE">
  246. <span id="_CPPv3I0DpEN3fmt19basic_format_stringE"></span><span id="_CPPv2I0DpEN3fmt19basic_format_stringE"></span>template&lt;typename <code class="sig-name descname">Char</code>, typename ...<code class="sig-name descname">Args</code>&gt;<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>
  247. <dd><p>A compile-time format string. </p>
  248. </dd></dl>
  249. <dl class="cpp type">
  250. <dt id="_CPPv4IDpEN3fmt13format_stringE">
  251. <span id="_CPPv3IDpEN3fmt13format_stringE"></span><span id="_CPPv2IDpEN3fmt13format_stringE"></span>template&lt;typename ...<code class="sig-name descname">Args</code>&gt;<br /><span class="target" id="core_8h_1af16a31148381bcd0452aad48560112aa"></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>&lt;char, type_identity_t&lt;<a class="reference internal" href="#_CPPv4IDpEN3fmt13format_stringE" title="fmt::format_string::Args">Args</a>&gt;...&gt;<a class="headerlink" href="#_CPPv4IDpEN3fmt13format_stringE" title="Permalink to this definition">¶</a><br /></dt>
  252. <dd></dd></dl>
  253. <dl class="cpp function">
  254. <dt id="_CPPv4N3fmt7runtimeE11string_view">
  255. <span id="_CPPv3N3fmt7runtimeE11string_view"></span><span id="_CPPv2N3fmt7runtimeE11string_view"></span><span id="fmt::runtime__string_view"></span><span class="target" id="core_8h_1aba0a335bf5875cf233d5a3b36b182610"></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> -&gt; basic_runtime&lt;char&gt;<a class="headerlink" href="#_CPPv4N3fmt7runtimeE11string_view" title="Permalink to this definition">¶</a><br /></dt>
  256. <dd><p><p><p>Creates a runtime format string.</p>
  257. <p><strong>Example</strong>:</p>
  258. <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="c1">// Check format string at runtime instead of compile-time.</span>
  259. <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">&quot;{:d}&quot;</span><span class="p">),</span><span class="w"> </span><span class="s">&quot;I am not a number&quot;</span><span class="p">);</span><span class="w"></span>
  260. </pre></div>
  261. </div>
  262. </p>
  263. </p>
  264. </dd></dl>
  265. </section>
  266. <section id="named-arguments">
  267. <h3>Named Arguments<a class="headerlink" href="#named-arguments" title="Permalink to this headline">¶</a></h3>
  268. <dl class="cpp function">
  269. <dt id="_CPPv4I00EN3fmt3argEN6detail9named_argI4Char1TEEPK4CharRK1T">
  270. <span id="_CPPv3I00EN3fmt3argEPK4CharRK1T"></span><span id="_CPPv2I00EN3fmt3argEPK4CharRK1T"></span>template&lt;typename <code class="sig-name descname">Char</code>, typename <code class="sig-name descname">T</code>&gt;<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> &amp;<em>arg</em><span class="sig-paren">)</span> -&gt; detail::named_arg&lt;<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>&gt;<a class="headerlink" href="#_CPPv4I00EN3fmt3argEN6detail9named_argI4Char1TEEPK4CharRK1T" title="Permalink to this definition">¶</a><br /></dt>
  271. <dd><p><p><p>Returns a named argument to be used in a formatting function.
  272. It should only be used in a call to a formatting function or
  273. <code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">dynamic_format_arg_store::push_back</span></code>.</p>
  274. <p><strong>Example</strong>:</p>
  275. <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">&quot;Elapsed time: {s:.2f} seconds&quot;</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">&quot;s&quot;</span><span class="p">,</span><span class="w"> </span><span class="mf">1.23</span><span class="p">));</span><span class="w"></span>
  276. </pre></div>
  277. </div>
  278. </p>
  279. </p>
  280. </dd></dl>
  281. <p>Named arguments are not supported in compile-time checks at the moment.</p>
  282. </section>
  283. <section id="argument-lists">
  284. <h3>Argument Lists<a class="headerlink" href="#argument-lists" title="Permalink to this headline">¶</a></h3>
  285. <p>You can create your own formatting function with compile-time checks and small
  286. binary footprint, for example (<a class="reference external" href="https://godbolt.org/z/oba4Mc">https://godbolt.org/z/oba4Mc</a>):</p>
  287. <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;fmt/format.h&gt;</span><span class="cp"></span>
  288. <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><span class="w"></span>
  289. <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><span class="w"></span>
  290. <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">&quot;{}: {}: &quot;</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><span class="w"></span>
  291. <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><span class="w"></span>
  292. <span class="p">}</span><span class="w"></span>
  293. <span class="k">template</span><span class="w"> </span><span class="o">&lt;</span><span class="k">typename</span><span class="w"> </span><span class="nc">S</span><span class="p">,</span><span class="w"> </span><span class="k">typename</span><span class="p">...</span><span class="w"> </span><span class="n">Args</span><span class="o">&gt;</span><span class="w"></span>
  294. <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="k">const</span><span class="w"> </span><span class="n">S</span><span class="o">&amp;</span><span class="w"> </span><span class="n">format</span><span class="p">,</span><span class="w"> </span><span class="n">Args</span><span class="o">&amp;&amp;</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><span class="w"></span>
  295. <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><span class="w"></span>
  296. <span class="p">}</span><span class="w"></span>
  297. <span class="cp">#define MY_LOG(format, ...) \</span>
  298. <span class="cp"> log(__FILE__, __LINE__, FMT_STRING(format), __VA_ARGS__)</span>
  299. <span class="n">MY_LOG</span><span class="p">(</span><span class="s">&quot;invalid squishiness: {}&quot;</span><span class="p">,</span><span class="w"> </span><span class="mi">42</span><span class="p">);</span><span class="w"></span>
  300. </pre></div>
  301. </div>
  302. <p>Note that <code class="docutils literal notranslate"><span class="pre">vlog</span></code> is not parameterized on argument types which improves compile
  303. times and reduces binary code size compared to a fully parameterized version.</p>
  304. <dl class="cpp function">
  305. <dt id="_CPPv4I0DpEN3fmt16make_format_argsE16format_arg_storeI7ContextDp14remove_cvref_tI4ArgsEEDpRR4Args">
  306. <span id="_CPPv3I0DpEN3fmt16make_format_argsEDpRR4Args"></span><span id="_CPPv2I0DpEN3fmt16make_format_argsEDpRR4Args"></span>template&lt;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">Args</code>&gt;<br /><span class="target" id="core_8h_1a2275a9ce83c8b30013dbceb22af36a04"></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_tI4ArgsEEDpRR4Args" title="fmt::make_format_args::Args">Args</a>&amp;&amp;... <em>args</em><span class="sig-paren">)</span> -&gt; <a class="reference internal" href="#_CPPv4I0DpEN3fmt16format_arg_storeE" title="fmt::format_arg_store">format_arg_store</a>&lt;<a class="reference internal" href="#_CPPv4I0DpEN3fmt16make_format_argsE16format_arg_storeI7ContextDp14remove_cvref_tI4ArgsEEDpRR4Args" title="fmt::make_format_args::Context">Context</a>, remove_cvref_t&lt;<a class="reference internal" href="#_CPPv4I0DpEN3fmt16make_format_argsE16format_arg_storeI7ContextDp14remove_cvref_tI4ArgsEEDpRR4Args" title="fmt::make_format_args::Args">Args</a>&gt;...&gt;<a class="headerlink" href="#_CPPv4I0DpEN3fmt16make_format_argsE16format_arg_storeI7ContextDp14remove_cvref_tI4ArgsEEDpRR4Args" title="Permalink to this definition">¶</a><br /></dt>
  307. <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
  308. 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_tI4ArgsEEDpRR4Args" title="fmt::make_format_args::Context"><code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">Context</span></code></a>
  309. can be omitted in which case it defaults to <code class="xref cpp cpp-any docutils literal notranslate"><span class="pre">context</span></code>.
  310. 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>
  311. </p>
  312. </p>
  313. </dd></dl>
  314. <dl class="cpp class">
  315. <dt id="_CPPv4I0DpEN3fmt16format_arg_storeE">
  316. <span id="_CPPv3I0DpEN3fmt16format_arg_storeE"></span><span id="_CPPv2I0DpEN3fmt16format_arg_storeE"></span>template&lt;typename <code class="sig-name descname">Context</code>, typename ...<code class="sig-name descname">Args</code>&gt;<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>
  317. <dd><p><p><p>An array of references to arguments. It can be implicitly converted into
  318. <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
  319. 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>
  320. </p>
  321. </p>
  322. </dd></dl>
  323. <dl class="cpp class">
  324. <dt id="_CPPv4I0EN3fmt24dynamic_format_arg_storeE">
  325. <span id="_CPPv3I0EN3fmt24dynamic_format_arg_storeE"></span><span id="_CPPv2I0EN3fmt24dynamic_format_arg_storeE"></span>template&lt;typename <code class="sig-name descname">Context</code>&gt;<br /><span class="target" id="classfmt_1_1dynamic__format__arg__store"></span><em class="property">class </em><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>
  326. <dd></dd></dl>
  327. <dl class="cpp class">
  328. <dt id="_CPPv4I0EN3fmt17basic_format_argsE">
  329. <span id="_CPPv3I0EN3fmt17basic_format_argsE"></span><span id="_CPPv2I0EN3fmt17basic_format_argsE"></span>template&lt;typename <code class="sig-name descname">Context</code>&gt;<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>
  330. <dd><p><p><p>A view of a collection of formatting arguments. To avoid lifetime issues it
  331. should only be used as a parameter type in type-erased functions such as
  332. <code class="docutils literal notranslate"><span class="pre">vformat</span></code>:</p>
  333. <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>
  334. <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="mi">42</span><span class="p">);</span><span class="w"> </span><span class="c1">// Error: dangling reference</span>
  335. </pre></div>
  336. </div>
  337. </p>
  338. </p>
  339. <div class="breathe-sectiondef docutils container">
  340. <p class="breathe-sectiondef-title rubric">Public Functions</p>
  341. <dl class="cpp function">
  342. <dt id="_CPPv4IDpEN3fmt17basic_format_args17basic_format_argsERK16format_arg_storeI7ContextDp4ArgsE">
  343. <span id="_CPPv3IDpEN3fmt17basic_format_args17basic_format_argsERK16format_arg_storeI7ContextDp4ArgsE"></span><span id="_CPPv2IDpEN3fmt17basic_format_args17basic_format_argsERK16format_arg_storeI7ContextDp4ArgsE"></span>template&lt;typename ...<code class="sig-name descname">Args</code>&gt;<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>&lt;<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>...&gt; &amp;<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>
  344. <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>
  345. </p>
  346. </p>
  347. </dd></dl>
  348. <dl class="cpp function">
  349. <dt id="_CPPv4N3fmt17basic_format_args17basic_format_argsERK24dynamic_format_arg_storeI7ContextE">
  350. <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>&lt;<a class="reference internal" href="#_CPPv4I0EN3fmt17basic_format_argsE" title="fmt::basic_format_args::Context">Context</a>&gt; &amp;<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>
  351. <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
  352. <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>
  353. </p>
  354. </p>
  355. </dd></dl>
  356. <dl class="cpp function">
  357. <dt id="_CPPv4N3fmt17basic_format_args17basic_format_argsEPK10format_argi">
  358. <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>
  359. <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>
  360. </p>
  361. </p>
  362. </dd></dl>
  363. <dl class="cpp function">
  364. <dt id="_CPPv4NK3fmt17basic_format_args3getEi">
  365. <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> -&gt; format_arg<a class="headerlink" href="#_CPPv4NK3fmt17basic_format_args3getEi" title="Permalink to this definition">¶</a><br /></dt>
  366. <dd><p>Returns the argument with the specified id. </p>
  367. </dd></dl>
  368. </div>
  369. </dd></dl>
  370. <dl class="cpp type">
  371. <dt id="_CPPv4N3fmt11format_argsE">
  372. <span id="_CPPv3N3fmt11format_argsE"></span><span id="_CPPv2N3fmt11format_argsE"></span><span class="target" id="core_8h_1a0144acf16386c7096f7254a6c5ff543d"></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>&lt;<a class="reference internal" href="#_CPPv4N3fmt14format_contextE" title="fmt::format_context">format_context</a>&gt;<a class="headerlink" href="#_CPPv4N3fmt11format_argsE" title="Permalink to this definition">¶</a><br /></dt>
  373. <dd><p>An alias to <code class="docutils literal notranslate"><span class="pre">basic_format_args&lt;format_context&gt;</span></code>. </p>
  374. </dd></dl>
  375. <dl class="cpp class">
  376. <dt id="_CPPv4I0EN3fmt16basic_format_argE">
  377. <span id="_CPPv3I0EN3fmt16basic_format_argE"></span><span id="_CPPv2I0EN3fmt16basic_format_argE"></span>template&lt;typename <code class="sig-name descname">Context</code>&gt;<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>
  378. <dd></dd></dl>
  379. <dl class="cpp class">
  380. <dt id="_CPPv4I00EN3fmt26basic_format_parse_contextE">
  381. <span id="_CPPv3I00EN3fmt26basic_format_parse_contextE"></span><span id="_CPPv2I00EN3fmt26basic_format_parse_contextE"></span>template&lt;typename <code class="sig-name descname">Char</code>, typename <code class="sig-name descname">ErrorHandler</code> = detail::error_handler&gt;<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> : <em class="property">private</em> fmt::detail::error_handler<a class="headerlink" href="#_CPPv4I00EN3fmt26basic_format_parse_contextE" title="Permalink to this definition">¶</a><br /></dt>
  382. <dd><p><p><p>Parsing context consisting of a format string range being parsed and an
  383. argument counter for automatic indexing.
  384. 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>
  385. </p>
  386. </p>
  387. <p>Subclassed by fmt::detail::compile_parse_context&lt; Char, ErrorHandler &gt;, fmt::basic_printf_parse_context&lt; Char &gt;</p>
  388. <div class="breathe-sectiondef docutils container">
  389. <p class="breathe-sectiondef-title rubric">Public Functions</p>
  390. <dl class="cpp function">
  391. <dt id="_CPPv4NK3fmt26basic_format_parse_context5beginEv">
  392. <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_1addd1866ffb39210fb90d576f99cc263d"></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> -&gt; iterator<a class="headerlink" href="#_CPPv4NK3fmt26basic_format_parse_context5beginEv" title="Permalink to this definition">¶</a><br /></dt>
  393. <dd><p>Returns an iterator to the beginning of the format string range being parsed. </p>
  394. </dd></dl>
  395. <dl class="cpp function">
  396. <dt id="_CPPv4NK3fmt26basic_format_parse_context3endEv">
  397. <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_1a9e47a32a9e32c573e99c2090ebd611f0"></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> -&gt; iterator<a class="headerlink" href="#_CPPv4NK3fmt26basic_format_parse_context3endEv" title="Permalink to this definition">¶</a><br /></dt>
  398. <dd><p>Returns an iterator past the end of the format string range being parsed. </p>
  399. </dd></dl>
  400. <dl class="cpp function">
  401. <dt id="_CPPv4N3fmt26basic_format_parse_context10advance_toE8iterator">
  402. <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_1aa8eaccff3a2ed5cdad3fe26601b02741"></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>
  403. <dd><p>Advances the begin iterator to <code class="docutils literal notranslate"><span class="pre">it</span></code>. </p>
  404. </dd></dl>
  405. <dl class="cpp function">
  406. <dt id="_CPPv4N3fmt26basic_format_parse_context11next_arg_idEv">
  407. <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_1a3d69b8e9c5e2b64a5b965c4d060cd6ae"></span>auto <code class="sig-name descname">next_arg_id</code><span class="sig-paren">(</span><span class="sig-paren">)</span> -&gt; int<a class="headerlink" href="#_CPPv4N3fmt26basic_format_parse_context11next_arg_idEv" title="Permalink to this definition">¶</a><br /></dt>
  408. <dd><p>Reports an error if using the manual argument indexing; otherwise returns the next argument index and switches to the automatic indexing. </p>
  409. </dd></dl>
  410. <dl class="cpp function">
  411. <dt id="_CPPv4N3fmt26basic_format_parse_context12check_arg_idEi">
  412. <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_1aeb1244edea8216733ad1ee861470d70a"></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>
  413. <dd><p>Reports an error if using the automatic argument indexing; otherwise switches to the manual indexing. </p>
  414. </dd></dl>
  415. </div>
  416. </dd></dl>
  417. <dl class="cpp class">
  418. <dt id="_CPPv4I00EN3fmt20basic_format_contextE">
  419. <span id="_CPPv3I00EN3fmt20basic_format_contextE"></span><span id="_CPPv2I00EN3fmt20basic_format_contextE"></span>template&lt;typename <code class="sig-name descname">OutputIt</code>, typename <code class="sig-name descname">Char</code>&gt;<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>
  420. <dd><div class="breathe-sectiondef docutils container">
  421. <p class="breathe-sectiondef-title rubric">Public Types</p>
  422. <dl class="cpp type">
  423. <dt id="_CPPv4N3fmt20basic_format_context9char_typeE">
  424. <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>
  425. <dd><p>The character type for the output. </p>
  426. </dd></dl>
  427. </div>
  428. <div class="breathe-sectiondef docutils container">
  429. <p class="breathe-sectiondef-title rubric">Public Functions</p>
  430. <dl class="cpp function">
  431. <dt id="_CPPv4N3fmt20basic_format_context20basic_format_contextE8OutputIt17basic_format_argsI20basic_format_contextEN6detail10locale_refE">
  432. <span id="_CPPv3N3fmt20basic_format_context20basic_format_contextE8OutputIt17basic_format_argsI20basic_format_contextEN6detail10locale_refE"></span><span id="_CPPv2N3fmt20basic_format_context20basic_format_contextE8OutputIt17basic_format_argsI20basic_format_contextEN6detail10locale_refE"></span><span id="fmt::basic_format_context::basic_format_context__OutputIt.basic_format_args:basic_format_context:.detail::locale_refCE"></span><span class="target" id="classfmt_1_1basic__format__context_1ac498674b757a934b3b6871829e831271"></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="#_CPPv4I0EN3fmt17basic_format_argsE" title="fmt::basic_format_args">basic_format_args</a>&lt;<a class="reference internal" href="#_CPPv4N3fmt20basic_format_context20basic_format_contextE8OutputIt17basic_format_argsI20basic_format_contextEN6detail10locale_refE" title="fmt::basic_format_context::basic_format_context">basic_format_context</a>&gt; <em>ctx_args</em>, detail::locale_ref <em>loc</em> = detail::locale_ref()<span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4N3fmt20basic_format_context20basic_format_contextE8OutputIt17basic_format_argsI20basic_format_contextEN6detail10locale_refE" title="Permalink to this definition">¶</a><br /></dt>
  433. <dd><p>Constructs a <code class="docutils literal notranslate"><span class="pre">basic_format_context</span></code> object. </p>
  434. <p>References to the arguments are stored in the object so make sure they have appropriate lifetimes. </p>
  435. </dd></dl>
  436. </div>
  437. </dd></dl>
  438. <dl class="cpp type">
  439. <dt id="_CPPv4N3fmt14format_contextE">
  440. <span id="_CPPv3N3fmt14format_contextE"></span><span id="_CPPv2N3fmt14format_contextE"></span><span class="target" id="core_8h_1a505aee3190baa15ea328dc731bfa476a"></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&lt;char&gt;<a class="headerlink" href="#_CPPv4N3fmt14format_contextE" title="Permalink to this definition">¶</a><br /></dt>
  441. <dd></dd></dl>
  442. </section>
  443. <section id="compatibility">
  444. <h3>Compatibility<a class="headerlink" href="#compatibility" title="Permalink to this headline">¶</a></h3>
  445. <dl class="cpp class">
  446. <dt id="_CPPv4I0EN3fmt17basic_string_viewE">
  447. <span id="_CPPv3I0EN3fmt17basic_string_viewE"></span><span id="_CPPv2I0EN3fmt17basic_string_viewE"></span>template&lt;typename <code class="sig-name descname">Char</code>&gt;<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>
  448. <dd><p>An implementation of <code class="docutils literal notranslate"><span class="pre">std::basic_string_view</span></code> for pre-C++17. </p>
  449. <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>
  450. <div class="breathe-sectiondef docutils container">
  451. <p class="breathe-sectiondef-title rubric">Public Functions</p>
  452. <dl class="cpp function">
  453. <dt id="_CPPv4N3fmt17basic_string_view17basic_string_viewEPK4Char6size_t">
  454. <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>
  455. <dd><p>Constructs a string reference object from a C string and a size. </p>
  456. </dd></dl>
  457. <dl class="cpp function">
  458. <dt id="_CPPv4N3fmt17basic_string_view17basic_string_viewEPK4Char">
  459. <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>
  460. <dd><p><p><p>Constructs a string reference object from a C string computing
  461. the size with <code class="docutils literal notranslate"><span class="pre">std::char_traits&lt;Char&gt;::length</span></code>.</p>
  462. </p>
  463. </p>
  464. </dd></dl>
  465. <dl class="cpp function">
  466. <dt id="_CPPv4I00EN3fmt17basic_string_view17basic_string_viewERKNSt12basic_stringI4Char6Traits5AllocEE">
  467. <span id="_CPPv3I00EN3fmt17basic_string_view17basic_string_viewERKNSt12basic_stringI4Char6Traits5AllocEE"></span><span id="_CPPv2I00EN3fmt17basic_string_view17basic_string_viewERKNSt12basic_stringI4Char6Traits5AllocEE"></span>template&lt;typename <code class="sig-name descname">Traits</code>, typename <code class="sig-name descname">Alloc</code>&gt;<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&lt;<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>&gt; &amp;<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>
  468. <dd><p>Constructs a string reference from a <code class="docutils literal notranslate"><span class="pre">std::basic_string</span></code> object. </p>
  469. </dd></dl>
  470. <dl class="cpp function">
  471. <dt id="_CPPv4NK3fmt17basic_string_view4dataEv">
  472. <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> -&gt; <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>
  473. <dd><p>Returns a pointer to the string data. </p>
  474. </dd></dl>
  475. <dl class="cpp function">
  476. <dt id="_CPPv4NK3fmt17basic_string_view4sizeEv">
  477. <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> -&gt; size_t<a class="headerlink" href="#_CPPv4NK3fmt17basic_string_view4sizeEv" title="Permalink to this definition">¶</a><br /></dt>
  478. <dd><p>Returns the string size. </p>
  479. </dd></dl>
  480. </div>
  481. </dd></dl>
  482. <dl class="cpp type">
  483. <dt id="_CPPv4N3fmt11string_viewE">
  484. <span id="_CPPv3N3fmt11string_viewE"></span><span id="_CPPv2N3fmt11string_viewE"></span><span class="target" id="core_8h_1a487c62e95b61a2543fc362ee4378dcaa"></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>&lt;char&gt;<a class="headerlink" href="#_CPPv4N3fmt11string_viewE" title="Permalink to this definition">¶</a><br /></dt>
  485. <dd></dd></dl>
  486. </section>
  487. <section id="locale">
  488. <h3>Locale<a class="headerlink" href="#locale" title="Permalink to this headline">¶</a></h3>
  489. <p>All formatting is locale-independent by default. Use the <code class="docutils literal notranslate"><span class="pre">'L'</span></code> format
  490. specifier to insert the appropriate number separator characters from the
  491. locale:</p>
  492. <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;fmt/core.h&gt;</span><span class="cp"></span>
  493. <span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;locale&gt;</span><span class="cp"></span>
  494. <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">&quot;en_US.UTF-8&quot;</span><span class="p">));</span><span class="w"></span>
  495. <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">&quot;{:L}&quot;</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 == &quot;1,000,000&quot;</span>
  496. </pre></div>
  497. </div>
  498. </section>
  499. </section>
  500. <section id="format-api">
  501. <span id="id2"></span><h2>Format API<a class="headerlink" href="#format-api" title="Permalink to this headline">¶</a></h2>
  502. <p><code class="docutils literal notranslate"><span class="pre">fmt/format.h</span></code> defines the full format API providing additional formatting
  503. functions and locale support.</p>
  504. <section id="formatting-user-defined-types">
  505. <span id="udt"></span><h3>Formatting User-Defined Types<a class="headerlink" href="#formatting-user-defined-types" title="Permalink to this headline">¶</a></h3>
  506. <p>The {fmt} library provides formatters for many standard C++ types.
  507. See <a class="reference internal" href="#ranges-api"><span class="std std-ref">fmt/ranges.h</span></a> for ranges and tuples including standard
  508. 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
  509. and time formatting and <a class="reference internal" href="#std-api"><span class="std std-ref">fmt/std.h</span></a> for path and variant
  510. formatting.</p>
  511. <p>To make a user-defined type formattable, specialize the <code class="docutils literal notranslate"><span class="pre">formatter&lt;T&gt;</span></code> struct
  512. template 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>
  513. <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;fmt/format.h&gt;</span><span class="cp"></span>
  514. <span class="k">struct</span><span class="w"> </span><span class="nc">point</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
  515. <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><span class="w"></span>
  516. <span class="p">};</span><span class="w"></span>
  517. <span class="k">template</span><span class="w"> </span><span class="o">&lt;&gt;</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">&lt;</span><span class="n">point</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
  518. <span class="w"> </span><span class="c1">// Presentation format: &#39;f&#39; - fixed, &#39;e&#39; - exponential.</span>
  519. <span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="n">presentation</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="sc">&#39;f&#39;</span><span class="p">;</span><span class="w"></span>
  520. <span class="w"> </span><span class="c1">// Parses format specifications of the form [&#39;f&#39; | &#39;e&#39;].</span>
  521. <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">&amp;</span><span class="w"> </span><span class="n">ctx</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="k">decltype</span><span class="p">(</span><span class="n">ctx</span><span class="p">.</span><span class="n">begin</span><span class="p">())</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
  522. <span class="w"> </span><span class="c1">// [ctx.begin(), ctx.end()) is a character range that contains a part of</span>
  523. <span class="w"> </span><span class="c1">// the format string starting from the format specifications to be parsed,</span>
  524. <span class="w"> </span><span class="c1">// e.g. in</span>
  525. <span class="w"> </span><span class="c1">//</span>
  526. <span class="w"> </span><span class="c1">// fmt::format(&quot;{:f} - point of interest&quot;, point{1, 2});</span>
  527. <span class="w"> </span><span class="c1">//</span>
  528. <span class="w"> </span><span class="c1">// the range will contain &quot;f} - point of interest&quot;. The formatter should</span>
  529. <span class="w"> </span><span class="c1">// parse specifiers until &#39;}&#39; or the end of the range. In this example</span>
  530. <span class="w"> </span><span class="c1">// the formatter should parse the &#39;f&#39; specifier and return an iterator</span>
  531. <span class="w"> </span><span class="c1">// pointing to &#39;}&#39;.</span>
  532. <span class="w"> </span><span class="c1">// Please also note that this character range may be empty, in case of</span>
  533. <span class="w"> </span><span class="c1">// the &quot;{}&quot; format string, so therefore you should check ctx.begin()</span>
  534. <span class="w"> </span><span class="c1">// for equality with ctx.end().</span>
  535. <span class="w"> </span><span class="c1">// Parse the presentation format and store it in the formatter:</span>
  536. <span class="w"> </span><span class="k">auto</span><span class="w"> </span><span class="n">it</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ctx</span><span class="p">.</span><span class="n">begin</span><span class="p">(),</span><span class="w"> </span><span class="n">end</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ctx</span><span class="p">.</span><span class="n">end</span><span class="p">();</span><span class="w"></span>
  537. <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">it</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="n">end</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="p">(</span><span class="o">*</span><span class="n">it</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="sc">&#39;f&#39;</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="o">*</span><span class="n">it</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="sc">&#39;e&#39;</span><span class="p">))</span><span class="w"> </span><span class="n">presentation</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">*</span><span class="n">it</span><span class="o">++</span><span class="p">;</span><span class="w"></span>
  538. <span class="w"> </span><span class="c1">// Check if reached the end of the range:</span>
  539. <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">it</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="n">end</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="o">*</span><span class="n">it</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="sc">&#39;}&#39;</span><span class="p">)</span><span class="w"> </span><span class="k">throw</span><span class="w"> </span><span class="n">format_error</span><span class="p">(</span><span class="s">&quot;invalid format&quot;</span><span class="p">);</span><span class="w"></span>
  540. <span class="w"> </span><span class="c1">// Return an iterator past the end of the parsed range:</span>
  541. <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">it</span><span class="p">;</span><span class="w"></span>
  542. <span class="w"> </span><span class="p">}</span><span class="w"></span>
  543. <span class="w"> </span><span class="c1">// Formats the point p using the parsed format specification (presentation)</span>
  544. <span class="w"> </span><span class="c1">// stored in this formatter.</span>
  545. <span class="w"> </span><span class="k">template</span><span class="w"> </span><span class="o">&lt;</span><span class="k">typename</span><span class="w"> </span><span class="nc">FormatContext</span><span class="o">&gt;</span><span class="w"></span>
  546. <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">&amp;</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">&amp;</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="o">-&gt;</span><span class="w"> </span><span class="k">decltype</span><span class="p">(</span><span class="n">ctx</span><span class="p">.</span><span class="n">out</span><span class="p">())</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
  547. <span class="w"> </span><span class="c1">// ctx.out() is an output iterator to write to.</span>
  548. <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">presentation</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="sc">&#39;f&#39;</span><span class="w"></span>
  549. <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_to</span><span class="p">(</span><span class="n">ctx</span><span class="p">.</span><span class="n">out</span><span class="p">(),</span><span class="w"> </span><span class="s">&quot;({:.1f}, {:.1f})&quot;</span><span class="p">,</span><span class="w"> </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">p</span><span class="p">.</span><span class="n">y</span><span class="p">)</span><span class="w"></span>
  550. <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_to</span><span class="p">(</span><span class="n">ctx</span><span class="p">.</span><span class="n">out</span><span class="p">(),</span><span class="w"> </span><span class="s">&quot;({:.1e}, {:.1e})&quot;</span><span class="p">,</span><span class="w"> </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">p</span><span class="p">.</span><span class="n">y</span><span class="p">);</span><span class="w"></span>
  551. <span class="w"> </span><span class="p">}</span><span class="w"></span>
  552. <span class="p">};</span><span class="w"></span>
  553. </pre></div>
  554. </div>
  555. <p>Then you can pass objects of type <code class="docutils literal notranslate"><span class="pre">point</span></code> to any formatting function:</p>
  556. <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="n">point</span><span class="w"> </span><span class="n">p</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>
  557. <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">&quot;{:f}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="p">);</span><span class="w"></span>
  558. <span class="c1">// s == &quot;(1.0, 2.0)&quot;</span>
  559. </pre></div>
  560. </div>
  561. <p>You can also reuse existing formatters via inheritance or composition, for
  562. example:</p>
  563. <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="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><span class="w"></span>
  564. <span class="k">template</span><span class="w"> </span><span class="o">&lt;&gt;</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">&lt;</span><span class="n">color</span><span class="o">&gt;:</span><span class="w"> </span><span class="n">formatter</span><span class="o">&lt;</span><span class="n">string_view</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
  565. <span class="w"> </span><span class="c1">// parse is inherited from formatter&lt;string_view&gt;.</span>
  566. <span class="w"> </span><span class="k">template</span><span class="w"> </span><span class="o">&lt;</span><span class="k">typename</span><span class="w"> </span><span class="nc">FormatContext</span><span class="o">&gt;</span><span class="w"></span>
  567. <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">FormatContext</span><span class="o">&amp;</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><span class="w"></span>
  568. <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">&quot;unknown&quot;</span><span class="p">;</span><span class="w"></span>
  569. <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><span class="w"></span>
  570. <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">&quot;red&quot;</span><span class="p">;</span><span class="w"> </span><span class="k">break</span><span class="p">;</span><span class="w"></span>
  571. <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">&quot;green&quot;</span><span class="p">;</span><span class="w"> </span><span class="k">break</span><span class="p">;</span><span class="w"></span>
  572. <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">&quot;blue&quot;</span><span class="p">;</span><span class="w"> </span><span class="k">break</span><span class="p">;</span><span class="w"></span>
  573. <span class="w"> </span><span class="p">}</span><span class="w"></span>
  574. <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">formatter</span><span class="o">&lt;</span><span class="n">string_view</span><span class="o">&gt;::</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><span class="w"></span>
  575. <span class="w"> </span><span class="p">}</span><span class="w"></span>
  576. <span class="p">};</span><span class="w"></span>
  577. </pre></div>
  578. </div>
  579. <p>Since <code class="docutils literal notranslate"><span class="pre">parse</span></code> is inherited from <code class="docutils literal notranslate"><span class="pre">formatter&lt;string_view&gt;</span></code> it will recognize
  580. all string format specifications, for example</p>
  581. <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">&quot;{:&gt;10}&quot;</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><span class="w"></span>
  582. </pre></div>
  583. </div>
  584. <p>will return <code class="docutils literal notranslate"><span class="pre">&quot;</span>&#160;&#160;&#160;&#160;&#160; <span class="pre">blue&quot;</span></code>.</p>
  585. <p>You can also write a formatter for a hierarchy of classes:</p>
  586. <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;type_traits&gt;</span><span class="cp"></span>
  587. <span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;fmt/format.h&gt;</span><span class="cp"></span>
  588. <span class="k">struct</span><span class="w"> </span><span class="nc">A</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
  589. <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><span class="w"></span>
  590. <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">&quot;A&quot;</span><span class="p">;</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
  591. <span class="p">};</span><span class="w"></span>
  592. <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><span class="w"></span>
  593. <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">&quot;B&quot;</span><span class="p">;</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
  594. <span class="p">};</span><span class="w"></span>
  595. <span class="k">template</span><span class="w"> </span><span class="o">&lt;</span><span class="k">typename</span><span class="w"> </span><span class="nc">T</span><span class="o">&gt;</span><span class="w"></span>
  596. <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">&lt;</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">&lt;</span><span class="n">std</span><span class="o">::</span><span class="n">is_base_of</span><span class="o">&lt;</span><span class="n">A</span><span class="p">,</span><span class="w"> </span><span class="n">T</span><span class="o">&gt;::</span><span class="n">value</span><span class="p">,</span><span class="w"> </span><span class="kt">char</span><span class="o">&gt;&gt;</span><span class="w"> </span><span class="o">:</span><span class="w"></span>
  597. <span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">formatter</span><span class="o">&lt;</span><span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
  598. <span class="w"> </span><span class="k">template</span><span class="w"> </span><span class="o">&lt;</span><span class="k">typename</span><span class="w"> </span><span class="nc">FormatCtx</span><span class="o">&gt;</span><span class="w"></span>
  599. <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">&amp;</span><span class="w"> </span><span class="n">a</span><span class="p">,</span><span class="w"> </span><span class="n">FormatCtx</span><span class="o">&amp;</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><span class="w"></span>
  600. <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">&lt;</span><span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">&gt;::</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><span class="w"></span>
  601. <span class="w"> </span><span class="p">}</span><span class="w"></span>
  602. <span class="p">};</span><span class="w"></span>
  603. <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><span class="w"></span>
  604. <span class="w"> </span><span class="n">B</span><span class="w"> </span><span class="n">b</span><span class="p">;</span><span class="w"></span>
  605. <span class="w"> </span><span class="n">A</span><span class="o">&amp;</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><span class="w"></span>
  606. <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">&quot;{}&quot;</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 &quot;B&quot;</span>
  607. <span class="p">}</span><span class="w"></span>
  608. </pre></div>
  609. </div>
  610. <p>If a type provides both a <code class="docutils literal notranslate"><span class="pre">formatter</span></code> specialization and an implicit
  611. conversion to a formattable type, the specialization takes precedence over the
  612. conversion.</p>
  613. <p>For enums {fmt} also provides the <code class="docutils literal notranslate"><span class="pre">format_as</span></code> extension API. To format an enum
  614. via this API define <code class="docutils literal notranslate"><span class="pre">format_as</span></code> that takes this enum and converts it to the
  615. underlying type. <code class="docutils literal notranslate"><span class="pre">format_as</span></code> should be defined in the same namespace as the
  616. enum.</p>
  617. <p>Example (<a class="reference external" href="https://godbolt.org/z/r7vvGE1v7">https://godbolt.org/z/r7vvGE1v7</a>):</p>
  618. <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;fmt/format.h&gt;</span><span class="cp"></span>
  619. <span class="k">namespace</span><span class="w"> </span><span class="nn">kevin_namespacy</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
  620. <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><span class="w"></span>
  621. <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><span class="w"></span>
  622. <span class="p">};</span><span class="w"></span>
  623. <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><span class="w"></span>
  624. <span class="p">}</span><span class="w"></span>
  625. <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><span class="w"></span>
  626. <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">&quot;{}</span><span class="se">\n</span><span class="s">&quot;</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 &quot;7&quot;</span>
  627. <span class="p">}</span><span class="w"></span>
  628. </pre></div>
  629. </div>
  630. </section>
  631. <section id="literal-based-api">
  632. <h3>Literal-Based API<a class="headerlink" href="#literal-based-api" title="Permalink to this headline">¶</a></h3>
  633. <p>The following user-defined literals are defined in <code class="docutils literal notranslate"><span class="pre">fmt/format.h</span></code>.</p>
  634. <dl class="cpp function">
  635. <dt id="_CPPv4I_N15detail_exported12fixed_stringEEN3fmtli2_aEDav">
  636. <span id="_CPPv3I_N15detail_exported12fixed_stringEEN3fmtli2_aEv"></span><span id="_CPPv2I_N15detail_exported12fixed_stringEEN3fmtli2_aEv"></span>template&lt;detail_exported::fixed_string <code class="sig-name descname">Str</code>&gt;<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&quot;&quot;_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>
  637. <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>
  638. <p><strong>Example</strong>:</p>
  639. <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><span class="w"></span>
  640. <span class="n">fmt</span><span class="o">::</span><span class="n">print</span><span class="p">(</span><span class="s">&quot;Elapsed time: {s:.2f} seconds&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;s&quot;</span><span class="n">_a</span><span class="o">=</span><span class="mf">1.23</span><span class="p">);</span><span class="w"></span>
  641. </pre></div>
  642. </div>
  643. </p>
  644. </p>
  645. </dd></dl>
  646. </section>
  647. <section id="utilities">
  648. <h3>Utilities<a class="headerlink" href="#utilities" title="Permalink to this headline">¶</a></h3>
  649. <dl class="cpp function">
  650. <dt id="_CPPv4I0EN3fmt3ptrEPKv1T">
  651. <span id="_CPPv3I0EN3fmt3ptrE1T"></span><span id="_CPPv2I0EN3fmt3ptrE1T"></span>template&lt;typename <code class="sig-name descname">T</code>&gt;<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> -&gt; <em class="property">const</em> void*<a class="headerlink" href="#_CPPv4I0EN3fmt3ptrEPKv1T" title="Permalink to this definition">¶</a><br /></dt>
  652. <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>
  653. <p><strong>Example</strong>:</p>
  654. <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">&quot;{}&quot;</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><span class="w"></span>
  655. </pre></div>
  656. </div>
  657. </p>
  658. </p>
  659. </dd></dl>
  660. <dl class="cpp function">
  661. <dt id="_CPPv4I0EN3fmt3ptrEPKvRKNSt10unique_ptrI1TEE">
  662. <span id="_CPPv3I0EN3fmt3ptrERKNSt10unique_ptrI1TEE"></span><span id="_CPPv2I0EN3fmt3ptrERKNSt10unique_ptrI1TEE"></span>template&lt;typename <code class="sig-name descname">T</code>&gt;<br /><span class="target" id="format_8h_1a979e8d2bff18ee7e226368801d5b2d61"></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&lt;<a class="reference internal" href="#_CPPv4I0EN3fmt3ptrEPKvRKNSt10unique_ptrI1TEE" title="fmt::ptr::T">T</a>&gt; &amp;<em>p</em><span class="sig-paren">)</span> -&gt; <em class="property">const</em> void*<a class="headerlink" href="#_CPPv4I0EN3fmt3ptrEPKvRKNSt10unique_ptrI1TEE" title="Permalink to this definition">¶</a><br /></dt>
  663. <dd></dd></dl>
  664. <dl class="cpp function">
  665. <dt id="_CPPv4I0EN3fmt3ptrEPKvRKNSt10shared_ptrI1TEE">
  666. <span id="_CPPv3I0EN3fmt3ptrERKNSt10shared_ptrI1TEE"></span><span id="_CPPv2I0EN3fmt3ptrERKNSt10shared_ptrI1TEE"></span>template&lt;typename <code class="sig-name descname">T</code>&gt;<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&lt;<a class="reference internal" href="#_CPPv4I0EN3fmt3ptrEPKvRKNSt10shared_ptrI1TEE" title="fmt::ptr::T">T</a>&gt; &amp;<em>p</em><span class="sig-paren">)</span> -&gt; <em class="property">const</em> void*<a class="headerlink" href="#_CPPv4I0EN3fmt3ptrEPKvRKNSt10shared_ptrI1TEE" title="Permalink to this definition">¶</a><br /></dt>
  667. <dd></dd></dl>
  668. <dl class="cpp function">
  669. <dt id="_CPPv4I0EN3fmt10underlyingE12underlying_tI4EnumE4Enum">
  670. <span id="_CPPv3I0EN3fmt10underlyingE4Enum"></span><span id="_CPPv2I0EN3fmt10underlyingE4Enum"></span>template&lt;typename <code class="sig-name descname">Enum</code>&gt;<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> -&gt; underlying_t&lt;<a class="reference internal" href="#_CPPv4I0EN3fmt10underlyingE12underlying_tI4EnumE4Enum" title="fmt::underlying::Enum">Enum</a>&gt;<a class="headerlink" href="#_CPPv4I0EN3fmt10underlyingE12underlying_tI4EnumE4Enum" title="Permalink to this definition">¶</a><br /></dt>
  671. <dd><p><p><p>Converts <code class="docutils literal notranslate"><span class="pre">e</span></code> to the underlying type.</p>
  672. <p><strong>Example</strong>:</p>
  673. <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><span class="w"></span>
  674. <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">&quot;{}&quot;</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><span class="w"></span>
  675. </pre></div>
  676. </div>
  677. </p>
  678. </p>
  679. </dd></dl>
  680. <dl class="cpp function">
  681. <dt id="_CPPv4I0EN3fmt9to_stringENSt6stringERK1T">
  682. <span id="_CPPv3I0EN3fmt9to_stringERK1T"></span><span id="_CPPv2I0EN3fmt9to_stringERK1T"></span>template&lt;typename <code class="sig-name descname">T</code>&gt;<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> &amp;<em>value</em><span class="sig-paren">)</span> -&gt; std::string<a class="headerlink" href="#_CPPv4I0EN3fmt9to_stringENSt6stringERK1T" title="Permalink to this definition">¶</a><br /></dt>
  683. <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>
  684. <p><strong>Example</strong>:</p>
  685. <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;fmt/format.h&gt;</span><span class="cp"></span>
  686. <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><span class="w"></span>
  687. </pre></div>
  688. </div>
  689. </p>
  690. </p>
  691. </dd></dl>
  692. <dl class="cpp function">
  693. <dt id="_CPPv4I0EN3fmt4joinE9join_viewIN6detail10iterator_tI5RangeEEN6detail10sentinel_tI5RangeEEERR5Range11string_view">
  694. <span id="_CPPv3I0EN3fmt4joinERR5Range11string_view"></span><span id="_CPPv2I0EN3fmt4joinERR5Range11string_view"></span>template&lt;typename <code class="sig-name descname">Range</code>&gt;<br /><span class="target" id="format_8h_1a6bcb993efacb2f2b423c408a7f99811a"></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> &amp;&amp;<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> -&gt; join_view&lt;detail::iterator_t&lt;<a class="reference internal" href="#_CPPv4I0EN3fmt4joinE9join_viewIN6detail10iterator_tI5RangeEEN6detail10sentinel_tI5RangeEEERR5Range11string_view" title="fmt::join::Range">Range</a>&gt;, detail::sentinel_t&lt;<a class="reference internal" href="#_CPPv4I0EN3fmt4joinE9join_viewIN6detail10iterator_tI5RangeEEN6detail10sentinel_tI5RangeEEERR5Range11string_view" title="fmt::join::Range">Range</a>&gt;&gt;<a class="headerlink" href="#_CPPv4I0EN3fmt4joinE9join_viewIN6detail10iterator_tI5RangeEEN6detail10sentinel_tI5RangeEEERR5Range11string_view" title="Permalink to this definition">¶</a><br /></dt>
  695. <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>
  696. <p><strong>Example</strong>:</p>
  697. <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">&lt;</span><span class="kt">int</span><span class="o">&gt;</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><span class="w"></span>
  698. <span class="n">fmt</span><span class="o">::</span><span class="n">print</span><span class="p">(</span><span class="s">&quot;{}&quot;</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">&quot;, &quot;</span><span class="p">));</span><span class="w"></span>
  699. <span class="c1">// Output: &quot;1, 2, 3&quot;</span>
  700. </pre></div>
  701. </div>
  702. <p><code class="docutils literal notranslate"><span class="pre">fmt::join</span></code> applies passed format specifiers to the range elements:</p>
  703. <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">&quot;{:02}&quot;</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">&quot;, &quot;</span><span class="p">));</span><span class="w"></span>
  704. <span class="c1">// Output: &quot;01, 02, 03&quot;</span>
  705. </pre></div>
  706. </div>
  707. </p>
  708. </p>
  709. </dd></dl>
  710. <dl class="cpp function">
  711. <dt id="_CPPv4I00EN3fmt4joinE9join_viewI2It8SentinelE2It8Sentinel11string_view">
  712. <span id="_CPPv3I00EN3fmt4joinE2It8Sentinel11string_view"></span><span id="_CPPv2I00EN3fmt4joinE2It8Sentinel11string_view"></span>template&lt;typename <code class="sig-name descname">It</code>, typename <code class="sig-name descname">Sentinel</code>&gt;<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> -&gt; join_view&lt;<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>&gt;<a class="headerlink" href="#_CPPv4I00EN3fmt4joinE9join_viewI2It8SentinelE2It8Sentinel11string_view" title="Permalink to this definition">¶</a><br /></dt>
  713. <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>
  714. </dd></dl>
  715. <dl class="cpp function">
  716. <dt id="_CPPv4I0EN3fmt12group_digitsE17group_digits_viewI1TE1T">
  717. <span id="_CPPv3I0EN3fmt12group_digitsE1T"></span><span id="_CPPv2I0EN3fmt12group_digitsE1T"></span>template&lt;typename <code class="sig-name descname">T</code>&gt;<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> -&gt; group_digits_view&lt;<a class="reference internal" href="#_CPPv4I0EN3fmt12group_digitsE17group_digits_viewI1TE1T" title="fmt::group_digits::T">T</a>&gt;<a class="headerlink" href="#_CPPv4I0EN3fmt12group_digitsE17group_digits_viewI1TE1T" title="Permalink to this definition">¶</a><br /></dt>
  718. <dd><p><p><p>Returns a view that formats an integer value using ‘,’ as a locale-independent
  719. thousands separator.</p>
  720. <p><strong>Example</strong>:</p>
  721. <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">&quot;{}&quot;</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><span class="w"></span>
  722. <span class="c1">// Output: &quot;12,345&quot;</span>
  723. </pre></div>
  724. </div>
  725. </p>
  726. </p>
  727. </dd></dl>
  728. <dl class="cpp class">
  729. <dt id="_CPPv4I0EN3fmt6detail6bufferE">
  730. <span id="_CPPv3I0EN3fmt6detail6bufferE"></span><span id="_CPPv2I0EN3fmt6detail6bufferE"></span>template&lt;typename <code class="sig-name descname">T</code>&gt;<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>
  731. <dd><p><p><p>A contiguous memory buffer with an optional growing ability. It is an internal
  732. 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>
  733. </p>
  734. </p>
  735. <p>Subclassed by <a class="reference internal" href="#classfmt_1_1basic__memory__buffer"><span class="std std-ref">fmt::basic_memory_buffer&lt; bigit, bigits_capacity &gt;</span></a>, <a class="reference internal" href="#classfmt_1_1basic__memory__buffer"><span class="std std-ref">fmt::basic_memory_buffer&lt; wchar_t &gt;</span></a>, <a class="reference internal" href="#classfmt_1_1basic__memory__buffer"><span class="std std-ref">fmt::basic_memory_buffer&lt; T, SIZE, Allocator &gt;</span></a>, fmt::detail::iterator_buffer&lt; OutputIt, T, Traits &gt;, fmt::detail::iterator_buffer&lt; T *, T &gt;, fmt::detail::iterator_buffer&lt; T *, T, fixed_buffer_traits &gt;</p>
  736. <div class="breathe-sectiondef docutils container">
  737. <p class="breathe-sectiondef-title rubric">Public Functions</p>
  738. <dl class="cpp function">
  739. <dt id="_CPPv4NK3fmt6detail6buffer4sizeEv">
  740. <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> -&gt; size_t<a class="headerlink" href="#_CPPv4NK3fmt6detail6buffer4sizeEv" title="Permalink to this definition">¶</a><br /></dt>
  741. <dd><p>Returns the size of this buffer. </p>
  742. </dd></dl>
  743. <dl class="cpp function">
  744. <dt id="_CPPv4NK3fmt6detail6buffer8capacityEv">
  745. <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> -&gt; size_t<a class="headerlink" href="#_CPPv4NK3fmt6detail6buffer8capacityEv" title="Permalink to this definition">¶</a><br /></dt>
  746. <dd><p>Returns the capacity of this buffer. </p>
  747. </dd></dl>
  748. <dl class="cpp function">
  749. <dt id="_CPPv4N3fmt6detail6buffer4dataEv">
  750. <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> -&gt; <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>
  751. <dd><p>Returns a pointer to the buffer data. </p>
  752. </dd></dl>
  753. <dl class="cpp function">
  754. <dt id="_CPPv4NK3fmt6detail6buffer4dataEv">
  755. <span id="_CPPv3NK3fmt6detail6buffer4dataEv"></span><span id="_CPPv2NK3fmt6detail6buffer4dataEv"></span><span id="fmt::detail::buffer::dataC"></span><span class="target" id="classfmt_1_1detail_1_1buffer_1a3e1655ac7956476a2d8f8f3a3e8f8e2b"></span>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> -&gt; <em class="property">const</em> <a class="reference internal" href="#_CPPv4I0EN3fmt6detail6bufferE" title="fmt::detail::buffer::T">T</a>*<a class="headerlink" href="#_CPPv4NK3fmt6detail6buffer4dataEv" title="Permalink to this definition">¶</a><br /></dt>
  756. <dd><p>Returns a pointer to the buffer data. </p>
  757. </dd></dl>
  758. <dl class="cpp function">
  759. <dt id="_CPPv4N3fmt6detail6buffer5clearEv">
  760. <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>
  761. <dd><p>Clears this buffer. </p>
  762. </dd></dl>
  763. <dl class="cpp function">
  764. <dt id="_CPPv4I0EN3fmt6detail6buffer6appendEvPK1UPK1U">
  765. <span id="_CPPv3I0EN3fmt6detail6buffer6appendEPK1UPK1U"></span><span id="_CPPv2I0EN3fmt6detail6buffer6appendEPK1UPK1U"></span>template&lt;typename <code class="sig-name descname">U</code>&gt;<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>
  766. <dd><p>Appends data to the end of the buffer. </p>
  767. </dd></dl>
  768. </div>
  769. </dd></dl>
  770. <dl class="cpp class">
  771. <dt id="_CPPv4I0_6size_t0EN3fmt19basic_memory_bufferE">
  772. <span id="_CPPv3I0_6size_t0EN3fmt19basic_memory_bufferE"></span><span id="_CPPv2I0_6size_t0EN3fmt19basic_memory_bufferE"></span>template&lt;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&lt;<a class="reference internal" href="#_CPPv4I0_6size_t0EN3fmt19basic_memory_bufferE" title="fmt::basic_memory_buffer::T">T</a>&gt;&gt;<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>&lt;<a class="reference internal" href="#_CPPv4I0_6size_t0EN3fmt19basic_memory_bufferE" title="fmt::basic_memory_buffer::T">T</a>&gt;<a class="headerlink" href="#_CPPv4I0_6size_t0EN3fmt19basic_memory_bufferE" title="Permalink to this definition">¶</a><br /></dt>
  773. <dd><p><p><p>A dynamically growing memory buffer for trivially copyable/constructible types
  774. with the first <code class="docutils literal notranslate"><span class="pre">SIZE</span></code> elements stored in the object itself.</p>
  775. <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>
  776. <p><strong>Example</strong>:</p>
  777. <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><span class="w"></span>
  778. <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">&quot;The answer is {}.&quot;</span><span class="p">,</span><span class="w"> </span><span class="mi">42</span><span class="p">);</span><span class="w"></span>
  779. </pre></div>
  780. </div>
  781. <p>This will append the following output to the <code class="docutils literal notranslate"><span class="pre">out</span></code> object:</p>
  782. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>The answer is 42.
  783. </pre></div>
  784. </div>
  785. <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>
  786. </p>
  787. </p>
  788. <div class="breathe-sectiondef docutils container">
  789. <p class="breathe-sectiondef-title rubric">Public Functions</p>
  790. <dl class="cpp function">
  791. <dt id="_CPPv4N3fmt19basic_memory_buffer19basic_memory_bufferERR19basic_memory_buffer">
  792. <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> &amp;&amp;<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>
  793. <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
  794. of the other object to it.</p>
  795. </p>
  796. </p>
  797. </dd></dl>
  798. <dl class="cpp function">
  799. <dt id="_CPPv4N3fmt19basic_memory_bufferaSERR19basic_memory_buffer">
  800. <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> &amp;&amp;<em>other</em><span class="sig-paren">)</span> <em class="property">noexcept</em> -&gt; <a class="reference internal" href="#_CPPv4I0_6size_t0EN3fmt19basic_memory_bufferE" title="fmt::basic_memory_buffer">basic_memory_buffer</a>&amp;<a class="headerlink" href="#_CPPv4N3fmt19basic_memory_bufferaSERR19basic_memory_buffer" title="Permalink to this definition">¶</a><br /></dt>
  801. <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>
  802. </p>
  803. </p>
  804. </dd></dl>
  805. <dl class="cpp function">
  806. <dt id="_CPPv4N3fmt19basic_memory_buffer6resizeE6size_t">
  807. <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>
  808. <dd><p>Resizes the buffer to contain <em>count</em> elements. </p>
  809. <p>If T is a POD type new elements may not be initialized. </p>
  810. </dd></dl>
  811. <dl class="cpp function">
  812. <dt id="_CPPv4N3fmt19basic_memory_buffer7reserveE6size_t">
  813. <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>
  814. <dd><p>Increases the buffer capacity to <em>new_capacity</em>. </p>
  815. </dd></dl>
  816. </div>
  817. <div class="breathe-sectiondef docutils container">
  818. <p class="breathe-sectiondef-title rubric">Protected Functions</p>
  819. <dl class="cpp function">
  820. <dt id="_CPPv4N3fmt19basic_memory_buffer4growE6size_t">
  821. <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>
  822. <dd><p>Increases the buffer capacity to hold at least <em>capacity</em> elements. </p>
  823. </dd></dl>
  824. </div>
  825. </dd></dl>
  826. </section>
  827. <section id="system-errors">
  828. <h3>System Errors<a class="headerlink" href="#system-errors" title="Permalink to this headline">¶</a></h3>
  829. <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
  830. system functions which set <code class="docutils literal notranslate"><span class="pre">errno</span></code>. Users should not make any assumptions
  831. about the value of <code class="docutils literal notranslate"><span class="pre">errno</span></code> being preserved by library functions.</p>
  832. <dl class="cpp function">
  833. <dt id="_CPPv4IDpEN3fmt12system_errorENSt12system_errorEi13format_stringIDp1TEDpRR1T">
  834. <span id="_CPPv3IDpEN3fmt12system_errorEi13format_stringIDp1TEDpRR1T"></span><span id="_CPPv2IDpEN3fmt12system_errorEi13format_stringIDp1TEDpRR1T"></span>template&lt;typename ...<code class="sig-name descname">T</code>&gt;<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>&lt;<a class="reference internal" href="#_CPPv4IDpEN3fmt12system_errorENSt12system_errorEi13format_stringIDp1TEDpRR1T" title="fmt::system_error::T">T</a>...&gt; <em>fmt</em>, <a class="reference internal" href="#_CPPv4IDpEN3fmt12system_errorENSt12system_errorEi13format_stringIDp1TEDpRR1T" title="fmt::system_error::T">T</a>&amp;&amp;... <em>args</em><span class="sig-paren">)</span> -&gt; std::system_error<a class="headerlink" href="#_CPPv4IDpEN3fmt12system_errorENSt12system_errorEi13format_stringIDp1TEDpRR1T" title="Permalink to this definition">¶</a><br /></dt>
  835. <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
  836. <code class="docutils literal notranslate"><span class="pre">fmt::format(fmt,</span> <span class="pre">args...)</span></code>.</p>
  837. <blockquote>
  838. <div><p><em>error_code</em> is a system error code as given by <code class="docutils literal notranslate"><span class="pre">errno</span></code>.</p>
  839. </div></blockquote>
  840. <p><strong>Example</strong>:</p>
  841. <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="c1">// This throws std::system_error with the description</span>
  842. <span class="c1">// cannot open file &#39;madeup&#39;: No such file or directory</span>
  843. <span class="c1">// or similar (system message may vary).</span>
  844. <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">&quot;madeup&quot;</span><span class="p">;</span><span class="w"></span>
  845. <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">&quot;r&quot;</span><span class="p">);</span><span class="w"></span>
  846. <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><span class="w"></span>
  847. <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">&quot;cannot open file &#39;{}&#39;&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">filename</span><span class="p">);</span><span class="w"></span>
  848. </pre></div>
  849. </div>
  850. </p>
  851. </p>
  852. </dd></dl>
  853. <dl class="cpp function">
  854. <dt id="_CPPv4N3fmt19format_system_errorERN6detail6bufferIcEEiPKc">
  855. <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>&lt;char&gt; &amp;<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>
  856. <dd><p><p><p>Formats an error message for an error returned by an operating system or a
  857. language runtime, for example a file opening error, and writes it to <em>out</em>.
  858. 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>
  859. 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>.
  860. It is implementation-defined but normally looks like:</p>
  861. <pre class="literal-block"><em>&lt;message&gt;</em>: <em>&lt;system-message&gt;</em></pre>
  862. <p>where <em>&lt;message&gt;</em> is the passed message and <em>&lt;system-message&gt;</em> is the system
  863. message corresponding to the error code.
  864. <em>error_code</em> is a system error code as given by <code class="docutils literal notranslate"><span class="pre">errno</span></code>.</p>
  865. </p>
  866. </p>
  867. </dd></dl>
  868. </section>
  869. <section id="custom-allocators">
  870. <h3>Custom Allocators<a class="headerlink" href="#custom-allocators" title="Permalink to this headline">¶</a></h3>
  871. <p>The {fmt} library supports custom dynamic memory allocators.
  872. A custom allocator class can be specified as a template argument to
  873. <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>
  874. <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><span class="w"></span>
  875. <span class="w"> </span><span class="n">fmt</span><span class="o">::</span><span class="n">basic_memory_buffer</span><span class="o">&lt;</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">&gt;</span><span class="p">;</span><span class="w"></span>
  876. </pre></div>
  877. </div>
  878. <p>It is also possible to write a formatting function that uses a custom
  879. allocator:</p>
  880. <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><span class="w"></span>
  881. <span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">basic_string</span><span class="o">&lt;</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">&lt;</span><span class="kt">char</span><span class="o">&gt;</span><span class="p">,</span><span class="w"> </span><span class="n">custom_allocator</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>
  882. <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><span class="w"></span>
  883. <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><span class="w"></span>
  884. <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><span class="w"></span>
  885. <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><span class="w"></span>
  886. <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><span class="w"></span>
  887. <span class="p">}</span><span class="w"></span>
  888. <span class="k">template</span><span class="w"> </span><span class="o">&lt;</span><span class="k">typename</span><span class="w"> </span><span class="p">...</span><span class="n">Args</span><span class="o">&gt;</span><span class="w"></span>
  889. <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><span class="w"></span>
  890. <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><span class="w"></span>
  891. <span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">Args</span><span class="o">&amp;</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><span class="w"></span>
  892. <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><span class="w"></span>
  893. <span class="p">}</span><span class="w"></span>
  894. </pre></div>
  895. </div>
  896. <p>The allocator will be used for the output container only. Formatting functions
  897. normally don’t do any allocations for built-in and string types except for
  898. non-default floating-point formatting that occasionally falls back on
  899. <code class="docutils literal notranslate"><span class="pre">sprintf</span></code>.</p>
  900. </section>
  901. </section>
  902. <section id="range-and-tuple-formatting">
  903. <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>
  904. <p>The library also supports convenient formatting of ranges and tuples:</p>
  905. <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;fmt/ranges.h&gt;</span><span class="cp"></span>
  906. <span class="n">std</span><span class="o">::</span><span class="n">tuple</span><span class="o">&lt;</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">&gt;</span><span class="w"> </span><span class="n">t</span><span class="p">{</span><span class="sc">&#39;a&#39;</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><span class="w"></span>
  907. <span class="c1">// Prints &quot;(&#39;a&#39;, 1, 2.0)&quot;</span>
  908. <span class="n">fmt</span><span class="o">::</span><span class="n">print</span><span class="p">(</span><span class="s">&quot;{}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">t</span><span class="p">);</span><span class="w"></span>
  909. </pre></div>
  910. </div>
  911. <p>NOTE: currently, the overload of <code class="docutils literal notranslate"><span class="pre">fmt::join</span></code> for iterables exists in the main
  912. <code class="docutils literal notranslate"><span class="pre">format.h</span></code> header, but expect this to change in the future.</p>
  913. <p>Using <code class="docutils literal notranslate"><span class="pre">fmt::join</span></code>, you can separate tuple elements with a custom separator:</p>
  914. <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;fmt/ranges.h&gt;</span><span class="cp"></span>
  915. <span class="n">std</span><span class="o">::</span><span class="n">tuple</span><span class="o">&lt;</span><span class="kt">int</span><span class="p">,</span><span class="w"> </span><span class="kt">char</span><span class="o">&gt;</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">&#39;a&#39;</span><span class="p">};</span><span class="w"></span>
  916. <span class="c1">// Prints &quot;1, a&quot;</span>
  917. <span class="n">fmt</span><span class="o">::</span><span class="n">print</span><span class="p">(</span><span class="s">&quot;{}&quot;</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">&quot;, &quot;</span><span class="p">));</span><span class="w"></span>
  918. </pre></div>
  919. </div>
  920. </section>
  921. <section id="date-and-time-formatting">
  922. <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>
  923. <p><code class="docutils literal notranslate"><span class="pre">fmt/chrono.h</span></code> provides formatters for</p>
  924. <ul class="simple">
  925. <li><p><a class="reference external" href="https://en.cppreference.com/w/cpp/chrono/duration">std::chrono::duration</a></p></li>
  926. <li><p><a class="reference external" href="https://en.cppreference.com/w/cpp/chrono/time_point">std::chrono::time_point</a></p></li>
  927. <li><p><a class="reference external" href="https://en.cppreference.com/w/cpp/chrono/c/tm">std::tm</a></p></li>
  928. </ul>
  929. <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>
  930. <p><strong>Example</strong>:</p>
  931. <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;fmt/chrono.h&gt;</span><span class="cp"></span>
  932. <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><span class="w"></span>
  933. <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><span class="w"></span>
  934. <span class="w"> </span><span class="c1">// Prints &quot;The date is 2020-11-07.&quot; (with the current date):</span>
  935. <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">&quot;The date is {:%Y-%m-%d}.&quot;</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><span class="w"></span>
  936. <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><span class="w"></span>
  937. <span class="w"> </span><span class="c1">// Prints &quot;Default format: 42s 100ms&quot;:</span>
  938. <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">&quot;Default format: {} {}</span><span class="se">\n</span><span class="s">&quot;</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><span class="w"></span>
  939. <span class="w"> </span><span class="c1">// Prints &quot;strftime-like format: 03:15:30&quot;:</span>
  940. <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">&quot;strftime-like format: {:%H:%M:%S}</span><span class="se">\n</span><span class="s">&quot;</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><span class="w"></span>
  941. <span class="p">}</span><span class="w"></span>
  942. </pre></div>
  943. </div>
  944. <dl class="cpp function">
  945. <dt id="_CPPv4N3fmt9localtimeENSt6time_tE">
  946. <span id="_CPPv3N3fmt9localtimeENSt6time_tE"></span><span id="_CPPv2N3fmt9localtimeENSt6time_tE"></span><span id="fmt::localtime__std::time_t"></span><span class="target" id="chrono_8h_1a5a6084b124ad167a65ce0a01209c2771"></span>std::tm <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><a class="headerlink" href="#_CPPv4N3fmt9localtimeENSt6time_tE" title="Permalink to this definition">¶</a><br /></dt>
  947. <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>
  948. <p>Unlike <code class="docutils literal notranslate"><span class="pre">std::localtime</span></code>, this function is thread-safe on most platforms. </p>
  949. </dd></dl>
  950. <dl class="cpp function">
  951. <dt id="_CPPv4N3fmt6gmtimeENSt6time_tE">
  952. <span id="_CPPv3N3fmt6gmtimeENSt6time_tE"></span><span id="_CPPv2N3fmt6gmtimeENSt6time_tE"></span><span id="fmt::gmtime__std::time_t"></span><span class="target" id="chrono_8h_1aa4daedca37ef22c6b073daa8b055d585"></span>std::tm <code class="sig-prename descclassname">fmt<code class="sig-prename descclassname">::</code></code><code class="sig-name descname">gmtime</code><span class="sig-paren">(</span>std::time_t <em>time</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4N3fmt6gmtimeENSt6time_tE" title="Permalink to this definition">¶</a><br /></dt>
  953. <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 Coordinated Universal Time (UTC). </p>
  954. <p>Unlike <code class="docutils literal notranslate"><span class="pre">std::gmtime</span></code>, this function is thread-safe on most platforms. </p>
  955. </dd></dl>
  956. </section>
  957. <section id="standard-library-types-formatting">
  958. <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>
  959. <p><code class="docutils literal notranslate"><span class="pre">fmt/std.h</span></code> provides formatters for:</p>
  960. <ul class="simple">
  961. <li><p><a class="reference external" href="https://en.cppreference.com/w/cpp/filesystem/path">std::filesystem::path</a></p></li>
  962. <li><p><a class="reference external" href="https://en.cppreference.com/w/cpp/thread/thread/id">std::thread::id</a></p></li>
  963. <li><p><a class="reference external" href="https://en.cppreference.com/w/cpp/utility/variant/monostate">std::monostate</a></p></li>
  964. <li><p><a class="reference external" href="https://en.cppreference.com/w/cpp/utility/variant/variant">std::variant</a></p></li>
  965. </ul>
  966. <section id="formatting-variants">
  967. <h3>Formatting Variants<a class="headerlink" href="#formatting-variants" title="Permalink to this headline">¶</a></h3>
  968. <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
  969. <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>
  970. <p><strong>Example</strong>:</p>
  971. <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;fmt/std.h&gt;</span><span class="cp"></span>
  972. <span class="n">std</span><span class="o">::</span><span class="n">variant</span><span class="o">&lt;</span><span class="kt">char</span><span class="p">,</span><span class="w"> </span><span class="kt">float</span><span class="o">&gt;</span><span class="w"> </span><span class="n">v0</span><span class="p">{</span><span class="sc">&#39;x&#39;</span><span class="p">};</span><span class="w"></span>
  973. <span class="c1">// Prints &quot;variant(&#39;x&#39;)&quot;</span>
  974. <span class="n">fmt</span><span class="o">::</span><span class="n">print</span><span class="p">(</span><span class="s">&quot;{}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">v0</span><span class="p">);</span><span class="w"></span>
  975. <span class="n">std</span><span class="o">::</span><span class="n">variant</span><span class="o">&lt;</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">&gt;</span><span class="w"> </span><span class="n">v1</span><span class="p">;</span><span class="w"></span>
  976. <span class="c1">// Prints &quot;variant(monostate)&quot;</span>
  977. </pre></div>
  978. </div>
  979. </section>
  980. </section>
  981. <section id="format-string-compilation">
  982. <span id="compile-api"></span><h2>Format String Compilation<a class="headerlink" href="#format-string-compilation" title="Permalink to this headline">¶</a></h2>
  983. <p><code class="docutils literal notranslate"><span class="pre">fmt/compile.h</span></code> provides format string compilation enabled via the
  984. <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
  985. 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
  986. efficient formatting code at compile-time. This supports arguments of built-in
  987. and string types as well as user-defined types with <code class="docutils literal notranslate"><span class="pre">constexpr</span></code> <code class="docutils literal notranslate"><span class="pre">parse</span></code>
  988. functions in their <code class="docutils literal notranslate"><span class="pre">formatter</span></code> specializations. Format string compilation can
  989. generate more binary code compared to the default API and is only recommended in
  990. places where formatting is a performance bottleneck.</p>
  991. <dl class="cpp macro">
  992. <dt id="c.FMT_COMPILE">
  993. <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>
  994. <dd><p><p><p>Converts a string literal <em>s</em> into a format string that will be parsed at
  995. compile time and converted into efficient formatting code. Requires C++17
  996. <code class="docutils literal notranslate"><span class="pre">constexpr</span> <span class="pre">if</span></code> compiler support.</p>
  997. <p><strong>Example</strong>:</p>
  998. <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>
  999. <span class="c1">// runtime format string processing.</span>
  1000. <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">&quot;{}&quot;</span><span class="p">),</span><span class="w"> </span><span class="mi">42</span><span class="p">);</span><span class="w"></span>
  1001. </pre></div>
  1002. </div>
  1003. </p>
  1004. </p>
  1005. </dd></dl>
  1006. <dl class="cpp function">
  1007. <dt id="_CPPv4I_N15detail_exported12fixed_stringEEN3fmtli3_cfEDav">
  1008. <span id="_CPPv3I_N15detail_exported12fixed_stringEEN3fmtli3_cfEv"></span><span id="_CPPv2I_N15detail_exported12fixed_stringEEN3fmtli3_cfEv"></span>template&lt;detail_exported::fixed_string <code class="sig-name descname">Str</code>&gt;<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&quot;&quot;_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>
  1009. <dd></dd></dl>
  1010. </section>
  1011. <section id="terminal-color-and-text-style">
  1012. <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>
  1013. <p><code class="docutils literal notranslate"><span class="pre">fmt/color.h</span></code> provides support for terminal color and text style output.</p>
  1014. <dl class="cpp function">
  1015. <dt id="_CPPv4I0DpEN3fmt5printEvRK10text_styleRK1SDpRK4Args">
  1016. <span id="_CPPv3I0DpEN3fmt5printERK10text_styleRK1SDpRK4Args"></span><span id="_CPPv2I0DpEN3fmt5printERK10text_styleRK1SDpRK4Args"></span>template&lt;typename <code class="sig-name descname">S</code>, typename ...<code class="sig-name descname">Args</code>&gt;<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 &amp;<em>ts</em>, <em class="property">const</em> <a class="reference internal" href="#_CPPv4I0DpEN3fmt5printEvRK10text_styleRK1SDpRK4Args" title="fmt::print::S">S</a> &amp;<em>format_str</em>, <em class="property">const</em> <a class="reference internal" href="#_CPPv4I0DpEN3fmt5printEvRK10text_styleRK1SDpRK4Args" title="fmt::print::Args">Args</a>&amp;... <em>args</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4I0DpEN3fmt5printEvRK10text_styleRK1SDpRK4Args" title="Permalink to this definition">¶</a><br /></dt>
  1017. <dd><p><p><p>Formats a string and prints it to stdout using ANSI escape sequences to
  1018. specify text formatting.</p>
  1019. <p><strong>Example</strong>:</p>
  1020. <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><span class="w"></span>
  1021. <span class="w"> </span><span class="s">&quot;Elapsed time: {0:.2f} seconds&quot;</span><span class="p">,</span><span class="w"> </span><span class="mf">1.23</span><span class="p">);</span><span class="w"></span>
  1022. </pre></div>
  1023. </div>
  1024. </p>
  1025. </p>
  1026. </dd></dl>
  1027. <dl class="cpp function">
  1028. <dt id="_CPPv4N3fmt2fgEN6detail10color_typeE">
  1029. <span id="_CPPv3N3fmt2fgEN6detail10color_typeE"></span><span id="_CPPv2N3fmt2fgEN6detail10color_typeE"></span><span id="fmt::fg__detail::color_type"></span><span class="target" id="color_8h_1ae562883659d1d3f838b051b582cf7744"></span>text_style <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><a class="headerlink" href="#_CPPv4N3fmt2fgEN6detail10color_typeE" title="Permalink to this definition">¶</a><br /></dt>
  1030. <dd><p>Creates a text style from the foreground (text) color. </p>
  1031. </dd></dl>
  1032. <dl class="cpp function">
  1033. <dt id="_CPPv4N3fmt2bgEN6detail10color_typeE">
  1034. <span id="_CPPv3N3fmt2bgEN6detail10color_typeE"></span><span id="_CPPv2N3fmt2bgEN6detail10color_typeE"></span><span id="fmt::bg__detail::color_type"></span><span class="target" id="color_8h_1a6620824c655d9578079f0a7389775bf4"></span>text_style <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><a class="headerlink" href="#_CPPv4N3fmt2bgEN6detail10color_typeE" title="Permalink to this definition">¶</a><br /></dt>
  1035. <dd><p>Creates a text style from the background color. </p>
  1036. </dd></dl>
  1037. <dl class="cpp function">
  1038. <dt id="_CPPv4I0EN3fmt6styledEN6detail10styled_argI14remove_cvref_tI1TEEERK1T10text_style">
  1039. <span id="_CPPv3I0EN3fmt6styledERK1T10text_style"></span><span id="_CPPv2I0EN3fmt6styledERK1T10text_style"></span>template&lt;typename <code class="sig-name descname">T</code>&gt;<br /><span class="target" id="color_8h_1a5b813d1f62f762566cbdf3dfbfe19f9b"></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> &amp;<em>value</em>, text_style <em>ts</em><span class="sig-paren">)</span> -&gt; detail::styled_arg&lt;remove_cvref_t&lt;<a class="reference internal" href="#_CPPv4I0EN3fmt6styledEN6detail10styled_argI14remove_cvref_tI1TEEERK1T10text_style" title="fmt::styled::T">T</a>&gt;&gt;<a class="headerlink" href="#_CPPv4I0EN3fmt6styledEN6detail10styled_argI14remove_cvref_tI1TEEERK1T10text_style" title="Permalink to this definition">¶</a><br /></dt>
  1040. <dd><p><p><p>Returns an argument that will be formatted using ANSI escape sequences,
  1041. to be used in a formatting function.</p>
  1042. <p><strong>Example</strong>:</p>
  1043. <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">&quot;Elapsed time: {0:.2f} seconds&quot;</span><span class="p">,</span><span class="w"></span>
  1044. <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><span class="w"></span>
  1045. <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><span class="w"></span>
  1046. </pre></div>
  1047. </div>
  1048. </p>
  1049. </p>
  1050. </dd></dl>
  1051. </section>
  1052. <section id="system-apis">
  1053. <span id="os-api"></span><h2>System APIs<a class="headerlink" href="#system-apis" title="Permalink to this headline">¶</a></h2>
  1054. <dl class="cpp class">
  1055. <dt id="_CPPv4N3fmt7ostreamE">
  1056. <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> : <em class="property">private</em> fmt::detail::<a class="reference internal" href="#_CPPv4I0EN3fmt6detail6bufferE" title="fmt::detail::buffer">buffer</a>&lt;char&gt;<a class="headerlink" href="#_CPPv4N3fmt7ostreamE" title="Permalink to this definition">¶</a><br /></dt>
  1057. <dd><p>A fast output stream which is not thread-safe. </p>
  1058. <div class="breathe-sectiondef docutils container">
  1059. <p class="breathe-sectiondef-title rubric">Public Functions</p>
  1060. <dl class="cpp function">
  1061. <dt id="_CPPv4IDpEN3fmt7ostream5printEv13format_stringIDp1TEDpRR1T">
  1062. <span id="_CPPv3IDpEN3fmt7ostream5printE13format_stringIDp1TEDpRR1T"></span><span id="_CPPv2IDpEN3fmt7ostream5printE13format_stringIDp1TEDpRR1T"></span>template&lt;typename ...<code class="sig-name descname">T</code>&gt;<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>&lt;<a class="reference internal" href="#_CPPv4IDpEN3fmt7ostream5printEv13format_stringIDp1TEDpRR1T" title="fmt::ostream::print::T">T</a>...&gt; <em>fmt</em>, <a class="reference internal" href="#_CPPv4IDpEN3fmt7ostream5printEv13format_stringIDp1TEDpRR1T" title="fmt::ostream::print::T">T</a>&amp;&amp;... <em>args</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4IDpEN3fmt7ostream5printEv13format_stringIDp1TEDpRR1T" title="Permalink to this definition">¶</a><br /></dt>
  1063. <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>
  1064. </dd></dl>
  1065. </div>
  1066. <div class="breathe-sectiondef docutils container">
  1067. <p class="breathe-sectiondef-title rubric">Friends</p>
  1068. <dl class="cpp function">
  1069. <dt id="_CPPv4IDpEN3fmt7ostream11output_fileE7ostream12cstring_viewDp1T">
  1070. <span id="_CPPv3IDpEN3fmt7ostream11output_fileE12cstring_viewDp1T"></span><span id="_CPPv2IDpEN3fmt7ostream11output_fileE12cstring_viewDp1T"></span>template&lt;typename ...<code class="sig-name descname">T</code>&gt;<br /><span class="target" id="classfmt_1_1ostream_1ae2b994bc71e34d2cfdcec7717985cb05"></span><a class="reference internal" href="#_CPPv4N3fmt7ostreamE" title="fmt::ostream">ostream</a> <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="headerlink" href="#_CPPv4IDpEN3fmt7ostream11output_fileE7ostream12cstring_viewDp1T" title="Permalink to this definition">¶</a><br /></dt>
  1071. <dd><p><p><p>Opens a file for writing. Supported parameters passed in <em>params</em>:</p>
  1072. <ul class="simple">
  1073. <li><p><code class="docutils literal notranslate"><span class="pre">&lt;integer&gt;</span></code>: Flags passed to <a class="reference external" href="https://pubs.opengroup.org/onlinepubs/007904875/functions/open.html">open</a>
  1074. (<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>
  1075. <li><p><code class="docutils literal notranslate"><span class="pre">buffer_size=&lt;integer&gt;</span></code>: Output buffer size</p></li>
  1076. </ul>
  1077. <p><strong>Example</strong>:</p>
  1078. <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">&quot;guide.txt&quot;</span><span class="p">);</span><span class="w"></span>
  1079. <span class="n">out</span><span class="p">.</span><span class="n">print</span><span class="p">(</span><span class="s">&quot;Don&#39;t {}&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;Panic&quot;</span><span class="p">);</span><span class="w"></span>
  1080. </pre></div>
  1081. </div>
  1082. </p>
  1083. </p>
  1084. </dd></dl>
  1085. </div>
  1086. </dd></dl>
  1087. </section>
  1088. <section id="std-ostream-support">
  1089. <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>
  1090. <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
  1091. user-defined types that have an overloaded insertion operator (<code class="docutils literal notranslate"><span class="pre">operator&lt;&lt;</span></code>).
  1092. In order to make a type formattable via <code class="docutils literal notranslate"><span class="pre">std::ostream</span></code> you should provide a
  1093. <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>
  1094. <div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;fmt/ostream.h&gt;</span><span class="cp"></span>
  1095. <span class="k">struct</span><span class="w"> </span><span class="nc">date</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
  1096. <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><span class="w"></span>
  1097. <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">&amp;</span><span class="w"> </span><span class="k">operator</span><span class="o">&lt;&lt;</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">ostream</span><span class="o">&amp;</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">&amp;</span><span class="w"> </span><span class="n">d</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
  1098. <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">&lt;&lt;</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">&lt;&lt;</span><span class="w"> </span><span class="sc">&#39;-&#39;</span><span class="w"> </span><span class="o">&lt;&lt;</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">&lt;&lt;</span><span class="w"> </span><span class="sc">&#39;-&#39;</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">d</span><span class="p">.</span><span class="n">day</span><span class="p">;</span><span class="w"></span>
  1099. <span class="w"> </span><span class="p">}</span><span class="w"></span>
  1100. <span class="p">};</span><span class="w"></span>
  1101. <span class="k">template</span><span class="w"> </span><span class="o">&lt;&gt;</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">&lt;</span><span class="n">date</span><span class="o">&gt;</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><span class="w"></span>
  1102. <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">&quot;The date is {}&quot;</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><span class="w"></span>
  1103. <span class="c1">// s == &quot;The date is 2012-12-9&quot;</span>
  1104. </pre></div>
  1105. </div>
  1106. <dl class="cpp function">
  1107. <dt id="_CPPv4I0EN3fmt8streamedEN6detail13streamed_viewI1TEERK1T">
  1108. <span id="_CPPv3I0EN3fmt8streamedERK1T"></span><span id="_CPPv2I0EN3fmt8streamedERK1T"></span>template&lt;typename <code class="sig-name descname">T</code>&gt;<br /><span class="target" id="ostream_8h_1a44fd703bec9e05e6ad83cdcb300d2b82"></span>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> &amp;<em>value</em><span class="sig-paren">)</span> -&gt; detail::streamed_view&lt;<a class="reference internal" href="#_CPPv4I0EN3fmt8streamedEN6detail13streamed_viewI1TEERK1T" title="fmt::streamed::T">T</a>&gt;<a class="headerlink" href="#_CPPv4I0EN3fmt8streamedEN6detail13streamed_viewI1TEERK1T" title="Permalink to this definition">¶</a><br /></dt>
  1109. <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&lt;&lt;</span></code>.</p>
  1110. <p><strong>Example</strong>:</p>
  1111. <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">&quot;Current thread id: {}</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span><span class="w"></span>
  1112. <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><span class="w"></span>
  1113. </pre></div>
  1114. </div>
  1115. </p>
  1116. </p>
  1117. </dd></dl>
  1118. <dl class="cpp function">
  1119. <dt id="_CPPv4IDpEN3fmt5printEvRNSt7ostreamE13format_stringIDp1TEDpRR1T">
  1120. <span id="_CPPv3IDpEN3fmt5printERNSt7ostreamE13format_stringIDp1TEDpRR1T"></span><span id="_CPPv2IDpEN3fmt5printERNSt7ostreamE13format_stringIDp1TEDpRR1T"></span>template&lt;typename ...<code class="sig-name descname">T</code>&gt;<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 &amp;<em>os</em>, <a class="reference internal" href="#_CPPv4IDpEN3fmt13format_stringE" title="fmt::format_string">format_string</a>&lt;<a class="reference internal" href="#_CPPv4IDpEN3fmt5printEvRNSt7ostreamE13format_stringIDp1TEDpRR1T" title="fmt::print::T">T</a>...&gt; <em>fmt</em>, <a class="reference internal" href="#_CPPv4IDpEN3fmt5printEvRNSt7ostreamE13format_stringIDp1TEDpRR1T" title="fmt::print::T">T</a>&amp;&amp;... <em>args</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4IDpEN3fmt5printEvRNSt7ostreamE13format_stringIDp1TEDpRR1T" title="Permalink to this definition">¶</a><br /></dt>
  1121. <dd><p><p><p>Prints formatted data to the stream <em>os</em>.</p>
  1122. <p><strong>Example</strong>:</p>
  1123. <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">&quot;Don&#39;t {}!&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;panic&quot;</span><span class="p">);</span><span class="w"></span>
  1124. </pre></div>
  1125. </div>
  1126. </p>
  1127. </p>
  1128. </dd></dl>
  1129. </section>
  1130. <section id="printf-formatting">
  1131. <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>
  1132. <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.
  1133. The following functions use <a class="reference external" href="https://pubs.opengroup.org/onlinepubs/009695399/functions/fprintf.html">printf format string syntax</a> with
  1134. the POSIX extension for positional arguments. Unlike their standard
  1135. counterparts, the <code class="docutils literal notranslate"><span class="pre">fmt</span></code> functions are type-safe and throw an exception if an
  1136. argument type doesn’t match its format specification.</p>
  1137. <dl class="cpp function">
  1138. <dt id="_CPPv4I0DpEN3fmt6printfEiRK1SDpRK1T">
  1139. <span id="_CPPv3I0DpEN3fmt6printfERK1SDpRK1T"></span><span id="_CPPv2I0DpEN3fmt6printfERK1SDpRK1T"></span>template&lt;typename <code class="sig-name descname">S</code>, typename ...<code class="sig-name descname">T</code>&gt;<br /><span class="target" id="printf_8h_1ae86f703f0ba1a668b29d86bb5d31b64c"></span>auto <code class="sig-prename descclassname"><a class="reference internal" href="#_CPPv4I0DpEN3fmt6printfEiRK1SDpRK1T" 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><em class="property">const</em> <a class="reference internal" href="#_CPPv4I0DpEN3fmt6printfEiRK1SDpRK1T" title="fmt::printf::S">S</a> &amp;<em>fmt</em>, <em class="property">const</em> <a class="reference internal" href="#_CPPv4I0DpEN3fmt6printfEiRK1SDpRK1T" title="fmt::printf::T">T</a>&amp;... <em>args</em><span class="sig-paren">)</span> -&gt; int<a class="headerlink" href="#_CPPv4I0DpEN3fmt6printfEiRK1SDpRK1T" title="Permalink to this definition">¶</a><br /></dt>
  1140. <dd><p><p><p>Prints formatted data to <code class="docutils literal notranslate"><span class="pre">stdout</span></code>.</p>
  1141. <p><strong>Example</strong>:</p>
  1142. <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">&quot;Elapsed time: %.2f seconds&quot;</span><span class="p">,</span><span class="w"> </span><span class="mf">1.23</span><span class="p">);</span><span class="w"></span>
  1143. </pre></div>
  1144. </div>
  1145. </p>
  1146. </p>
  1147. </dd></dl>
  1148. <dl class="cpp function">
  1149. <dt id="_CPPv4I0Dp0EN3fmt7fprintfEiPNSt4FILEERK1SDpRK1T">
  1150. <span id="_CPPv3I0Dp0EN3fmt7fprintfEPNSt4FILEERK1SDpRK1T"></span><span id="_CPPv2I0Dp0EN3fmt7fprintfEPNSt4FILEERK1SDpRK1T"></span>template&lt;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&lt;<a class="reference internal" href="#_CPPv4I0Dp0EN3fmt7fprintfEiPNSt4FILEERK1SDpRK1T" title="fmt::fprintf::S">S</a>&gt;&gt;<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> &amp;<em>fmt</em>, <em class="property">const</em> <a class="reference internal" href="#_CPPv4I0Dp0EN3fmt7fprintfEiPNSt4FILEERK1SDpRK1T" title="fmt::fprintf::T">T</a>&amp;... <em>args</em><span class="sig-paren">)</span> -&gt; int<a class="headerlink" href="#_CPPv4I0Dp0EN3fmt7fprintfEiPNSt4FILEERK1SDpRK1T" title="Permalink to this definition">¶</a><br /></dt>
  1151. <dd><p><p><p>Prints formatted data to the file <em>f</em>.</p>
  1152. <p><strong>Example</strong>:</p>
  1153. <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">&quot;Don&#39;t %s!&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;panic&quot;</span><span class="p">);</span><span class="w"></span>
  1154. </pre></div>
  1155. </div>
  1156. </p>
  1157. </p>
  1158. </dd></dl>
  1159. <dl class="cpp function">
  1160. <dt id="_CPPv4I0Dp0EN3fmt7sprintfENSt12basic_stringI4CharEERK1SDpRK1T">
  1161. <span id="_CPPv3I0Dp0EN3fmt7sprintfERK1SDpRK1T"></span><span id="_CPPv2I0Dp0EN3fmt7sprintfERK1SDpRK1T"></span>template&lt;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&lt;detail::is_string&lt;<a class="reference internal" href="#_CPPv4I0Dp0EN3fmt7sprintfENSt12basic_stringI4CharEERK1SDpRK1T" title="fmt::sprintf::S">S</a>&gt;::value, char_t&lt;<a class="reference internal" href="#_CPPv4I0Dp0EN3fmt7sprintfENSt12basic_stringI4CharEERK1SDpRK1T" title="fmt::sprintf::S">S</a>&gt;&gt;&gt;<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> &amp;<em>fmt</em>, <em class="property">const</em> <a class="reference internal" href="#_CPPv4I0Dp0EN3fmt7sprintfENSt12basic_stringI4CharEERK1SDpRK1T" title="fmt::sprintf::T">T</a>&amp;... <em>args</em><span class="sig-paren">)</span> -&gt; std::basic_string&lt;<a class="reference internal" href="#_CPPv4I0Dp0EN3fmt7sprintfENSt12basic_stringI4CharEERK1SDpRK1T" title="fmt::sprintf::Char">Char</a>&gt;<a class="headerlink" href="#_CPPv4I0Dp0EN3fmt7sprintfENSt12basic_stringI4CharEERK1SDpRK1T" title="Permalink to this definition">¶</a><br /></dt>
  1162. <dd><p><p><p>Formats arguments and returns the result as a string.</p>
  1163. <p><strong>Example</strong>:</p>
  1164. <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">&quot;The answer is %d&quot;</span><span class="p">,</span><span class="w"> </span><span class="mi">42</span><span class="p">);</span><span class="w"></span>
  1165. </pre></div>
  1166. </div>
  1167. </p>
  1168. </p>
  1169. </dd></dl>
  1170. </section>
  1171. <section id="wchar-t-support">
  1172. <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>
  1173. <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
  1174. character types.</p>
  1175. <dl class="cpp struct">
  1176. <dt id="_CPPv4I0EN3fmt7is_charE">
  1177. <span id="_CPPv3I0EN3fmt7is_charE"></span><span id="_CPPv2I0EN3fmt7is_charE"></span>template&lt;typename <code class="sig-name descname">T</code>&gt;<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>
  1178. <dd><p>Specifies if <code class="docutils literal notranslate"><span class="pre">T</span></code> is a character type. </p>
  1179. <p>Can be specialized by users. </p>
  1180. </dd></dl>
  1181. <dl class="cpp type">
  1182. <dt id="_CPPv4N3fmt12wstring_viewE">
  1183. <span id="_CPPv3N3fmt12wstring_viewE"></span><span id="_CPPv2N3fmt12wstring_viewE"></span><span class="target" id="xchar_8h_1a9e27d5144b365f9f9028f921213a1113"></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>&lt;wchar_t&gt;<a class="headerlink" href="#_CPPv4N3fmt12wstring_viewE" title="Permalink to this definition">¶</a><br /></dt>
  1184. <dd></dd></dl>
  1185. <dl class="cpp type">
  1186. <dt id="_CPPv4N3fmt15wformat_contextE">
  1187. <span id="_CPPv3N3fmt15wformat_contextE"></span><span id="_CPPv2N3fmt15wformat_contextE"></span><span class="target" id="xchar_8h_1ad5fc003f598c0fbc5751d4f9882b5070"></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&lt;wchar_t&gt;<a class="headerlink" href="#_CPPv4N3fmt15wformat_contextE" title="Permalink to this definition">¶</a><br /></dt>
  1188. <dd></dd></dl>
  1189. <dl class="cpp function">
  1190. <dt id="_CPPv4I0EN3fmt10to_wstringENSt7wstringERK1T">
  1191. <span id="_CPPv3I0EN3fmt10to_wstringERK1T"></span><span id="_CPPv2I0EN3fmt10to_wstringERK1T"></span>template&lt;typename <code class="sig-name descname">T</code>&gt;<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> &amp;<em>value</em><span class="sig-paren">)</span> -&gt; std::wstring<a class="headerlink" href="#_CPPv4I0EN3fmt10to_wstringENSt7wstringERK1T" title="Permalink to this definition">¶</a><br /></dt>
  1192. <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>
  1193. </dd></dl>
  1194. </section>
  1195. <section id="compatibility-with-c-20-std-format">
  1196. <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>
  1197. <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
  1198. differences:</p>
  1199. <ul class="simple">
  1200. <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
  1201. collisions with standard library implementations.</p></li>
  1202. <li><p>Width calculation doesn’t use grapheme clusterization. The latter has been
  1203. implemented in a separate branch but hasn’t been integrated yet.</p></li>
  1204. <li><p>Most C++20 chrono types are not supported yet.</p></li>
  1205. </ul>
  1206. </section>
  1207. </section>
  1208. </div>
  1209. </div>
  1210. </div>
  1211. <div class="footer" role="contentinfo">
  1212. &copy; Copyright 2012-present, Victor Zverovich.
  1213. Created using <a href="http://sphinx-doc.org/">Sphinx</a> 3.3.0.
  1214. </div>
  1215. <script src="_static/bootstrap.min.js"></script>
  1216. </body>
  1217. </html>