Files
toml11/docs/features/toml_spec/index.html
ToruNiina e671b8e3bd Merge pull request #291 from franzpoeschel/namespace-versioning
Use an inline namespace to distinguish emitted symbols by version numbers e4051f77d7
2025-05-17 07:21:19 +00:00

83 lines
18 KiB
HTML

<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
TOML Language Version
#
You can specify the version of the TOML language and individual feature flags to use with toml::parse or toml::format through toml::spec.
Specifying TOML Version
#
You can construct a toml::spec from toml::semantic_version.
#include <toml.hpp>
int main()
{
toml::spec spec(toml::semantic_version(1, 1, 0));
return 0;
}
However, to make this shorter, the toml::spec::v() function is provided.
#include <toml.hpp>
int main()
{
toml::spec spec = toml::spec::v(1, 1, 0);
return 0;
}
If not specified explicitly, toml::spec::default_version() is used to construct with default values."><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/features/toml_spec/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="toml spec"><meta property="og:description" content="TOML Language Version # You can specify the version of the TOML language and individual feature flags to use with toml::parse or toml::format through toml::spec.
Specifying TOML Version # You can construct a toml::spec from toml::semantic_version.
#include <toml.hpp> int main() { toml::spec spec(toml::semantic_version(1, 1, 0)); return 0; } However, to make this shorter, the toml::spec::v() function is provided.
#include <toml.hpp> int main() { toml::spec spec = toml::spec::v(1, 1, 0); return 0; } If not specified explicitly, toml::spec::default_version() is used to construct with default values."><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>toml spec | toml11</title>
<link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/features/toml_spec/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/features/toml_spec/ title="toml spec"><link rel=stylesheet href=/toml11/book.min.ddac3efe7ea4c1007ff53e5a8fd67f12517e5d2e99984d8c67a18668f7ecaa03.css integrity="sha256-3aw+/n6kwQB/9T5aj9Z/ElF+XS6ZmE2MZ6GGaPfsqgM=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.db4a558804ac41f081539588cec8e4a415587801da466728166bb5341dd62411.js integrity="sha256-20pViASsQfCBU5WIzsjkpBVYeAHaRmcoFmu1NB3WJBE=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/features/toml_spec/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle checked>
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/ class=active>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle>
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
</label><strong>toml spec</strong>
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#toml-language-version>TOML Language Version</a><ul><li><a href=#specifying-toml-version>Specifying TOML Version</a><ul><li><a href=#parsing-with-version-specification>Parsing with Version Specification</a></li><li><a href=#serializing-with-version-specification>Serializing with Version Specification</a></li></ul></li><li><a href=#specifying-newly-added-features-in-toml>Specifying Newly Added Features in TOML</a></li></ul></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=toml-language-version>TOML Language Version
<a class=anchor href=#toml-language-version>#</a></h1><p>You can specify the version of the TOML language and individual feature flags to use with <code>toml::parse</code> or <code>toml::format</code> through <a href=https://toruniina.github.io/toml11/docs/reference/spec/#tomlspec><code>toml::spec</code></a>.</p><h2 id=specifying-toml-version>Specifying TOML Version
<a class=anchor href=#specifying-toml-version>#</a></h2><p>You can construct a <a href=https://toruniina.github.io/toml11/docs/reference/spec/#tomlspec><code>toml::spec</code></a> from <a href=https://toruniina.github.io/toml11/docs/reference/spec/#tomlsemantic_version><code>toml::semantic_version</code></a>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e>&lt;toml.hpp&gt;</span><span style=color:#75715e>
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
</span></span><span style=display:flex><span>{
</span></span><span style=display:flex><span> toml<span style=color:#f92672>::</span>spec spec(toml<span style=color:#f92672>::</span>semantic_version(<span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>0</span>));
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><p>However, to make this shorter, the <code>toml::spec::v()</code> function is provided.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e>&lt;toml.hpp&gt;</span><span style=color:#75715e>
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
</span></span><span style=display:flex><span>{
</span></span><span style=display:flex><span> toml<span style=color:#f92672>::</span>spec spec <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>spec<span style=color:#f92672>::</span>v(<span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>0</span>);
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><p>If not specified explicitly, <code>toml::spec::default_version()</code> is used to construct with default values.</p><p>The default value depends on the version of toml11 and follows the latest version of the TOML language released at that time.</p><p>As of v4.4.0, TOML v1.1.0 has not been released yet, so the default TOML version is v1.0.0.</p><blockquote class="book-hint warning"><p>Some features of TOML v1.1.0 are still under fairly lengthy discussion and may still be reverted.</p><p>If they are indeed reverted, toml11 will remove those features in a minor version upgrade or move them to a corresponding later version.</p><p>As such, any features related to future versions should be considered unstable.</p></blockquote><h3 id=parsing-with-version-specification>Parsing with Version Specification
<a class=anchor href=#parsing-with-version-specification>#</a></h3><p>The overload of <a href=https://toruniina.github.io/toml11/docs/reference/parser/#parse><code>toml::parse</code></a> takes a <code>toml::spec</code> following the file name.</p><p>This allows you to change the TOML version being used.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e>&lt;toml.hpp&gt;</span><span style=color:#75715e>
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
</span></span><span style=display:flex><span>{
</span></span><span style=display:flex><span> toml<span style=color:#f92672>::</span>value input <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse(<span style=color:#e6db74>&#34;input.toml&#34;</span>, toml<span style=color:#f92672>::</span>spec<span style=color:#f92672>::</span>v(<span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>0</span>));
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><h3 id=serializing-with-version-specification>Serializing with Version Specification
<a class=anchor href=#serializing-with-version-specification>#</a></h3><p>The overload of <a href=https://toruniina.github.io/toml11/docs/reference/serializer/><code>toml::format</code></a> takes a <code>toml::spec</code> following the <code>toml::value</code>.</p><p>This allows you to change the TOML version being used.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e>&lt;toml.hpp&gt;</span><span style=color:#75715e>
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
</span></span><span style=display:flex><span>{
</span></span><span style=display:flex><span> toml<span style=color:#f92672>::</span>value v <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse(<span style=color:#e6db74>&#34;input.toml&#34;</span>, toml<span style=color:#f92672>::</span>spec<span style=color:#f92672>::</span>v(<span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>0</span>));
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cout <span style=color:#f92672>&lt;&lt;</span> toml<span style=color:#f92672>::</span>format(v, toml<span style=color:#f92672>::</span>spec<span style=color:#f92672>::</span>v(<span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>0</span>)) <span style=color:#f92672>&lt;&lt;</span> std<span style=color:#f92672>::</span>endl;
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><p>If a format is passed that is not permitted by the provided <code>toml::spec</code>, it will be ignored, and another format will be used as a fallback.</p><h2 id=specifying-newly-added-features-in-toml>Specifying Newly Added Features in TOML
<a class=anchor href=#specifying-newly-added-features-in-toml>#</a></h2><p>With version upgrades in TOML, multiple new features are introduced, and it&rsquo;s possible to enable only some of them.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e>&lt;toml.hpp&gt;</span><span style=color:#75715e>
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
</span></span><span style=display:flex><span>{
</span></span><span style=display:flex><span> toml<span style=color:#f92672>::</span>spec spec <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>spec<span style=color:#f92672>::</span>v(<span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>0</span>, <span style=color:#ae81ff>0</span>);
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span> <span style=color:#75715e>// Allowing newlines in inline tables
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> spec.v1_1_0_allow_newlines_in_inline_tables <span style=color:#f92672>=</span> true;
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span> toml<span style=color:#f92672>::</span>value input <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse(<span style=color:#e6db74>&#34;input.toml&#34;</span>, spec);
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><p>For a full list of all flags, refer to <a href=https://toruniina.github.io/toml11/docs/reference/spec/#tomlspec><code>toml::spec</code></a>.</p></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#toml-language-version>TOML Language Version</a><ul><li><a href=#specifying-toml-version>Specifying TOML Version</a><ul><li><a href=#parsing-with-version-specification>Parsing with Version Specification</a></li><li><a href=#serializing-with-version-specification>Serializing with Version Specification</a></li></ul></li><li><a href=#specifying-newly-added-features-in-toml>Specifying Newly Added Features in TOML</a></li></ul></li></ul></nav></div></aside></main></body></html>