Merge pull request #295 from franzpoeschel/undef-source-location

Add a way to optionally suppress usage of std::source_location b96acf96ba
This commit is contained in:
ToruNiina
2025-12-03 15:01:09 +00:00
commit 360850a8c8
193 changed files with 19543 additions and 0 deletions

View File

@@ -0,0 +1,132 @@
<!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="
find.hpp
#
This function searches for a value in a toml::value and performs type conversion if necessary.
toml::value can change the type it stores, and toml::find accommodates these types.
Technically, all functions use toml::basic_value<TC>.
However, for simplicity, we refer to it as toml::value in explanations unless a distinction is necessary.
In the documentation, if the template parameter TC changes the type, assume that types like toml::value::integer_type will also change accordingly.
toml::find
#
Overview
#
toml::find uses template arguments for the type you want to retrieve and function arguments for the key of the value you want to find."><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/reference/find/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="find.hpp"><meta property="og:description" content="find.hpp # This function searches for a value in a toml::value and performs type conversion if necessary.
toml::value can change the type it stores, and toml::find accommodates these types. Technically, all functions use toml::basic_value<TC>. However, for simplicity, we refer to it as toml::value in explanations unless a distinction is necessary. In the documentation, if the template parameter TC changes the type, assume that types like toml::value::integer_type will also change accordingly. toml::find # Overview # toml::find uses template arguments for the type you want to retrieve and function arguments for the key of the value you want to find."><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>find.hpp | 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/reference/find/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/reference/find/ title=find.hpp><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" 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/reference/find/>日本語</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>
<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/>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 checked>
<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/ class=active>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>find.hpp</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=#findhpp>find.hpp</a></li><li><a href=#tomlfind><code>toml::find</code></a><ul><li><a href=#overview>Overview</a><ul><li><a href=#note-on-recursive-search>Note on Recursive Search</a></li></ul></li><li><a href=#tomlfindvalue-key><code>toml::find(value, key)</code></a><ul><li><a href=#exceptions>Exceptions</a></li></ul></li><li><a href=#tomlfindvalue-index><code>toml::find(value, index)</code></a><ul><li><a href=#exceptions-1>Exceptions</a></li></ul></li><li><a href=#tomlfindvalue-keys><code>toml::find(value, keys...)</code></a></li></ul></li><li><a href=#tomlfind_orvalue-key-fallback><code>toml::find_or(value, key, fallback)</code></a><ul><li><a href=#when-t-is-basic_value>When <code>T</code> is <code>basic_value</code></a></li><li><a href=#when-t-is-tomlvaluesome_type>When <code>T</code> is <code>toml::value::{some_type}</code></a></li><li><a href=#when-t-is-const-char>When <code>T</code> is <code>const char*</code></a></li><li><a href=#when-t-is-any-other-type>When <code>T</code> is any other type</a></li><li><a href=#when-multiple-keys-are-provided>When multiple keys are provided</a></li></ul></li><li><a href=#related>Related</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=findhpp>find.hpp
<a class=anchor href=#findhpp>#</a></h1><p>This function searches for a value in a <code>toml::value</code> and performs type conversion if necessary.</p><blockquote class="book-hint info"><code>toml::value</code> can change the type it stores, and <code>toml::find</code> accommodates these types.
Technically, all functions use <code>toml::basic_value&lt;TC></code>.
However, for simplicity, we refer to it as <code>toml::value</code> in explanations unless a distinction is necessary.
In the documentation, if the template parameter <code>TC</code> changes the type, assume that types like <code>toml::value::integer_type</code> will also change accordingly.</blockquote><h1 id=tomlfind><code>toml::find</code>
<a class=anchor href=#tomlfind>#</a></h1><h2 id=overview>Overview
<a class=anchor href=#overview>#</a></h2><p><code>toml::find</code> uses template arguments for the type you want to retrieve and function arguments for the key of the value you want to find.</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:#66d9ef>template</span><span style=color:#f92672>&lt;</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC, <span style=color:#66d9ef>typename</span> ... Keys<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span>T find(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;&amp;</span> v, Keys ... keys);
</span></span></code></pre></div><p>The supported types for <code>T</code> and the behavior of the conversion are the same as for <code>toml::get</code>.</p><p>If <code>T</code> is not specified, a <code>toml::value</code> will be returned.</p><p>Keys can be of type <code>toml::value::key_type</code> or <code>std::size_t</code>.
When multiple keys are provided, the function will search recursively through sub-tables or arrays.
If a <code>toml::value::key_type</code> is given, <code>toml::value</code> is interpreted as a <code>toml::table</code>; if a <code>std::size_t</code> is given, <code>toml::value</code> is interpreted as a <code>toml::array</code>.</p><h3 id=note-on-recursive-search>Note on Recursive Search
<a class=anchor href=#note-on-recursive-search>#</a></h3><p>TOML allows for bare keys as well as quoted keys (enclosed in <code>"</code> or <code>'</code>). Using a quoted key like <code>"foo.bar" = "baz"</code> means no sub-table is constructed, and the key is <code>"foo.bar"</code>. To handle such patterns, toml11 does not split keys containing <code>.</code> and searches using the full string.</p><p>Consider the following TOML file:</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-toml data-lang=toml><span style=display:flex><span>[<span style=color:#a6e22e>foo</span>]
</span></span><span style=display:flex><span>[<span style=color:#a6e22e>foo</span>.<span style=color:#a6e22e>bar</span>]
</span></span><span style=display:flex><span><span style=color:#a6e22e>baz</span> = <span style=color:#e6db74>&#34;hoge&#34;</span>
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span>[<span style=color:#e6db74>&#34;foo.bar&#34;</span>]
</span></span><span style=display:flex><span><span style=color:#a6e22e>baz</span> = <span style=color:#e6db74>&#34;fuga&#34;</span>
</span></span></code></pre></div><p>The corresponding usage of <code>toml::find</code> is shown below:</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:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> input <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse(<span style=color:#e6db74>&#34;input.toml&#34;</span>);
</span></span><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> baz1 <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>find<span style=color:#f92672>&lt;</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>&gt;</span>(input, <span style=color:#e6db74>&#34;foo&#34;</span>, <span style=color:#e6db74>&#34;bar&#34;</span>, <span style=color:#e6db74>&#34;baz&#34;</span>); <span style=color:#75715e>// hoge
</span></span></span><span style=display:flex><span><span style=color:#75715e></span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> baz2 <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>find<span style=color:#f92672>&lt;</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>&gt;</span>(input, <span style=color:#e6db74>&#34;foo.bar&#34;</span>, <span style=color:#e6db74>&#34;baz&#34;</span>); <span style=color:#75715e>// fuga
</span></span></span></code></pre></div><p>cf. <a href=https://toml.io/en/v1.0.0#keys>toml.io/en/v1.0.0#keys</a></p><h2 id=tomlfindvalue-key><code>toml::find(value, key)</code>
<a class=anchor href=#tomlfindvalue-key>#</a></h2><p>Searches for <code>key</code> in <code>value</code> as if <code>value</code> were a <code>toml::table</code>, then converts using <code>toml::get</code>.</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:#66d9ef>template</span><span style=color:#f92672>&lt;</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span><span style=color:#75715e>/* Equivalent to toml::get&lt;T&gt;(const value&amp;) */</span> find(
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;&amp;</span> v, <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>typename</span> basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;::</span>key_type<span style=color:#f92672>&amp;</span> ky);
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672>&lt;</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span><span style=color:#75715e>/* Equivalent to toml::get&lt;T&gt;(value&amp;) */</span> find(
</span></span><span style=display:flex><span> basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;&amp;</span> v, <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>typename</span> basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;::</span>key_type<span style=color:#f92672>&amp;</span> ky);
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672>&lt;</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span><span style=color:#75715e>/* Equivalent to toml::get&lt;T&gt;(value&amp;&amp;) */</span> find(
</span></span><span style=display:flex><span> basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;&amp;&amp;</span> v, <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>typename</span> basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;::</span>key_type<span style=color:#f92672>&amp;</span> ky);
</span></span></code></pre></div><p>If <code>T</code> is not specified, the function returns a <code>toml::value</code> without conversion.</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:#66d9ef>template</span><span style=color:#f92672>&lt;</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;</span> <span style=color:#66d9ef>const</span><span style=color:#f92672>&amp;</span> find(
</span></span><span style=display:flex><span> basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;</span> <span style=color:#66d9ef>const</span><span style=color:#f92672>&amp;</span> v, <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>typename</span> basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;::</span>key_type<span style=color:#f92672>&amp;</span> ky);
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672>&lt;</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;&amp;</span> find(
</span></span><span style=display:flex><span> basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;&amp;</span> v, <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>typename</span> basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;::</span>key_type<span style=color:#f92672>&amp;</span> ky);
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672>&lt;</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;</span> find(
</span></span><span style=display:flex><span> basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;&amp;&amp;</span> v, <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>typename</span> basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;::</span>key_type<span style=color:#f92672>&amp;</span> ky);
</span></span></code></pre></div><h3 id=exceptions>Exceptions
<a class=anchor href=#exceptions>#</a></h3><p>If the <code>toml::value</code> does not contain a <code>table</code>, a <code>toml::type_error</code> is thrown.</p><p>If the contained <code>table</code> does not have the specified element, a <code>std::out_of_range</code> is thrown.</p><p>If the specified element cannot be converted to <code>T</code> (i.e., <code>toml::get</code> fails), a <code>toml::type_error</code> is thrown.</p><h2 id=tomlfindvalue-index><code>toml::find(value, index)</code>
<a class=anchor href=#tomlfindvalue-index>#</a></h2><p>Accesses the <code>index</code>-th element of <code>value</code> as if <code>value</code> were a <code>toml::array</code>, then converts using <code>toml::get</code>.</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:#66d9ef>template</span><span style=color:#f92672>&lt;</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span><span style=color:#75715e>/* Equivalent to toml::get&lt;T&gt;(const value&amp;) */</span> find(
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;&amp;</span> v, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>size_t index);
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672>&lt;</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span><span style=color:#75715e>/* Equivalent to toml::get&lt;T&gt;(value&amp;) */</span> find(
</span></span><span style=display:flex><span> basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;&amp;</span> v, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>size_t index);
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672>&lt;</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span><span style=color:#75715e>/* Equivalent to toml::get&lt;T&gt;(value&amp;&amp;) */</span> find(
</span></span><span style=display:flex><span> basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;&amp;&amp;</span> v, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>size_t index);
</span></span></code></pre></div><p>If <code>T</code> is not specified, the function returns a <code>toml::value</code> without conversion.</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:#66d9ef>template</span><span style=color:#f92672>&lt;</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;</span> <span style=color:#66d9ef>const</span><span style=color:#f92672>&amp;</span> find(basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;</span> <span style=color:#66d9ef>const</span><span style=color:#f92672>&amp;</span> v, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>size_t ky);
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672>&lt;</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;&amp;</span> find(basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;&amp;</span> v, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>size_t ky);
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672>&lt;</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;</span> find(basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;&amp;&amp;</span> v, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>size_t ky);
</span></span></code></pre></div><h3 id=exceptions-1>Exceptions
<a class=anchor href=#exceptions-1>#</a></h3><p>If the <code>toml::value</code> does not contain an <code>array</code>, a <code>toml::type_error</code> is thrown.</p><p>If the contained <code>array</code> does not have the specified number of elements, a <code>std::out_of_range</code> is thrown.</p><p>If the specified element cannot be converted to <code>T</code> (i.e., <code>toml::get</code> fails), a <code>toml::type_error</code> is thrown.</p><h2 id=tomlfindvalue-keys><code>toml::find(value, keys...)</code>
<a class=anchor href=#tomlfindvalue-keys>#</a></h2><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:#66d9ef>template</span><span style=color:#f92672>&lt;</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC, <span style=color:#66d9ef>typename</span> K1, <span style=color:#66d9ef>typename</span> K2, <span style=color:#66d9ef>typename</span> ... Ks<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span><span style=color:#75715e>/* Equivalent to toml::get&lt;T&gt;(const value&amp;) */</span> find(
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;&amp;</span> v, <span style=color:#66d9ef>const</span> K1<span style=color:#f92672>&amp;</span> k1, <span style=color:#66d9ef>const</span> K2<span style=color:#f92672>&amp;</span> k2, <span style=color:#66d9ef>const</span> Ks<span style=color:#f92672>&amp;</span> ... ks);
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672>&lt;</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC, <span style=color:#66d9ef>typename</span> K1, <span style=color:#66d9ef>typename</span> K2, <span style=color:#66d9ef>typename</span> ... Ks<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span><span style=color:#75715e>/* Equivalent to toml::get&lt;T&gt;(value&amp;) */</span> find(
</span></span><span style=display:flex><span> basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;&amp;</span> v, <span style=color:#66d9ef>const</span> K1<span style=color:#f92672>&amp;</span> k1, <span style=color:#66d9ef>const</span> K2<span style=color:#f92672>&amp;</span> k2, <span style=color:#66d9ef>const</span> Ks<span style=color:#f92672>&amp;</span> ... ks);
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672>&lt;</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC, <span style=color:#66d9ef>typename</span> K1, <span style=color:#66d9ef>typename</span> K2, <span style=color:#66d9ef>typename</span> ... Ks<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span><span style=color:#75715e>/* Equivalent to toml::get&lt;T&gt;(value&amp;&amp;) */</span> find(
</span></span><span style=display:flex><span> basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;&amp;&amp;</span> v, <span style=color:#66d9ef>const</span> K1<span style=color:#f92672>&amp;</span> k1, <span style=color:#66d9ef>const</span> K2<span style=color:#f92672>&amp;</span> k2, <span style=color:#66d9ef>const</span> Ks<span style=color:#f92672>&amp;</span> ... ks);
</span></span></code></pre></div><p>This function calls <code>toml::find</code> recursively.</p><p>The failure conditions and the exceptions thrown are the same as those for <code>toml::find</code>.</p><h1 id=tomlfind_orvalue-key-fallback><code>toml::find_or(value, key, fallback)</code>
<a class=anchor href=#tomlfind_orvalue-key-fallback>#</a></h1><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:#66d9ef>template</span><span style=color:#f92672>&lt;</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC, <span style=color:#66d9ef>typename</span> Key<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span>T find_or(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;&amp;</span> v, <span style=color:#66d9ef>const</span> Key<span style=color:#f92672>&amp;</span> key, T<span style=color:#f92672>&amp;&amp;</span> opt);
</span></span></code></pre></div><p>The <code>find_or</code> function takes a default value to avoid throwing an exception when the search fails.</p><p>The default value must be of the same type as the return type <code>T</code>. Therefore, unlike <code>toml::find&lt;T></code>, <code>find_or</code> infers the type <code>T</code>.</p><p>You can specify <code>T</code> explicitly with <code>find_or&lt;T></code>, but this always returns a new value. To obtain a reference, do not specify <code>T</code>.</p><h2 id=when-t-is-basic_value>When <code>T</code> is <code>basic_value</code>
<a class=anchor href=#when-t-is-basic_value>#</a></h2><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:#66d9ef>template</span><span style=color:#f92672>&lt;</span><span style=color:#66d9ef>typename</span> TC, <span style=color:#66d9ef>typename</span> K<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;&amp;</span> find_or(basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;&amp;</span> v, <span style=color:#66d9ef>const</span> K<span style=color:#f92672>&amp;</span> key, basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;&amp;</span> opt) <span style=color:#66d9ef>noexcept</span>
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672>&lt;</span><span style=color:#66d9ef>typename</span> TC, <span style=color:#66d9ef>typename</span> K<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;</span> <span style=color:#66d9ef>const</span><span style=color:#f92672>&amp;</span> find_or(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;&amp;</span> v, <span style=color:#66d9ef>const</span> K<span style=color:#f92672>&amp;</span> key, <span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;&amp;</span> opt) <span style=color:#66d9ef>noexcept</span>
</span></span></code></pre></div><p>Searches for the corresponding value and returns it without conversion. Because no conversion is needed, a reference can be returned.</p><p>If the value is not found, the default value is returned.</p><h2 id=when-t-is-tomlvaluesome_type>When <code>T</code> is <code>toml::value::{some_type}</code>
<a class=anchor href=#when-t-is-tomlvaluesome_type>#</a></h2><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:#66d9ef>template</span><span style=color:#f92672>&lt;</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC, <span style=color:#66d9ef>typename</span> K<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span>T<span style=color:#f92672>&amp;</span> find_or(basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;&amp;</span> v, <span style=color:#66d9ef>const</span> K<span style=color:#f92672>&amp;</span> key, T<span style=color:#f92672>&amp;</span> opt) <span style=color:#66d9ef>noexcept</span>
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672>&lt;</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC, <span style=color:#66d9ef>typename</span> K<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span>T <span style=color:#66d9ef>const</span><span style=color:#f92672>&amp;</span> find_or(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;&amp;</span> v, <span style=color:#66d9ef>const</span> K<span style=color:#f92672>&amp;</span> key, <span style=color:#66d9ef>const</span> T<span style=color:#f92672>&amp;</span> opt) <span style=color:#66d9ef>noexcept</span>
</span></span></code></pre></div><p>Searches for the corresponding value and returns it without conversion. Because no conversion is needed, a reference can be returned.</p><p>If the value is not found or if a different type is stored, the default value is returned.</p><h2 id=when-t-is-const-char>When <code>T</code> is <code>const char*</code>
<a class=anchor href=#when-t-is-const-char>#</a></h2><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:#66d9ef>template</span><span style=color:#f92672>&lt;</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC, <span style=color:#66d9ef>typename</span> K<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span>T find_or(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;&amp;</span> v, <span style=color:#66d9ef>const</span> K<span style=color:#f92672>&amp;</span> key, T opt)
</span></span></code></pre></div><p>Searches for the corresponding value and returns it as a <code>std::string</code>.</p><p>Since the fallback is constructed from <code>const char*</code> to <code>std::string</code>, a reference cannot be returned in case of failure.</p><h2 id=when-t-is-any-other-type>When <code>T</code> is any other type
<a class=anchor href=#when-t-is-any-other-type>#</a></h2><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:#66d9ef>template</span><span style=color:#f92672>&lt;</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC, <span style=color:#66d9ef>typename</span> K<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span>T find_or(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;&amp;</span> v, <span style=color:#66d9ef>const</span> K<span style=color:#f92672>&amp;</span> key, T opt);
</span></span></code></pre></div><p>Searches for the corresponding value and converts it to <code>T</code> before returning it.</p><p>Because conversion is performed, a reference cannot be returned.</p><h2 id=when-multiple-keys-are-provided>When multiple keys are provided
<a class=anchor href=#when-multiple-keys-are-provided>#</a></h2><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:#66d9ef>template</span><span style=color:#f92672>&lt;</span><span style=color:#66d9ef>typename</span> Value, <span style=color:#66d9ef>typename</span> K1, <span style=color:#66d9ef>typename</span> K2, <span style=color:#66d9ef>typename</span> K3, <span style=color:#66d9ef>typename</span> ... Ks<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span><span style=color:#66d9ef>auto</span> find_or(Value<span style=color:#f92672>&amp;&amp;</span> v, <span style=color:#66d9ef>const</span> K1<span style=color:#f92672>&amp;</span> k1, <span style=color:#66d9ef>const</span> K2<span style=color:#f92672>&amp;</span> k2, K3<span style=color:#f92672>&amp;&amp;</span> k3, Ks<span style=color:#f92672>&amp;&amp;</span> ... keys) <span style=color:#66d9ef>noexcept</span>
</span></span><span style=display:flex><span> <span style=color:#f92672>-&gt;</span> <span style=color:#66d9ef>decltype</span>(find_or(v, k2, std<span style=color:#f92672>::</span>forward<span style=color:#f92672>&lt;</span>K3<span style=color:#f92672>&gt;</span>(k3), std<span style=color:#f92672>::</span>forward<span style=color:#f92672>&lt;</span>Ks<span style=color:#f92672>&gt;</span>(keys)...))
</span></span></code></pre></div><p>Interprets the last element in the key sequence as the default value and applies <code>find_or</code> recursively.</p><p>If the inferred type of <code>T</code> is <code>toml::value</code> or <code>toml::value::some_type</code>, a reference can be returned.</p><p>If <code>T</code> is explicitly specified, conversion is always performed.</p><h1 id=related>Related
<a class=anchor href=#related>#</a></h1><ul><li><a href=https://toruniina.github.io/toml11/docs/reference/get/>get.hpp</a></li><li><a href=https://toruniina.github.io/toml11/docs/reference/value/>value.hpp</a></li></ul></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=#findhpp>find.hpp</a></li><li><a href=#tomlfind><code>toml::find</code></a><ul><li><a href=#overview>Overview</a><ul><li><a href=#note-on-recursive-search>Note on Recursive Search</a></li></ul></li><li><a href=#tomlfindvalue-key><code>toml::find(value, key)</code></a><ul><li><a href=#exceptions>Exceptions</a></li></ul></li><li><a href=#tomlfindvalue-index><code>toml::find(value, index)</code></a><ul><li><a href=#exceptions-1>Exceptions</a></li></ul></li><li><a href=#tomlfindvalue-keys><code>toml::find(value, keys...)</code></a></li></ul></li><li><a href=#tomlfind_orvalue-key-fallback><code>toml::find_or(value, key, fallback)</code></a><ul><li><a href=#when-t-is-basic_value>When <code>T</code> is <code>basic_value</code></a></li><li><a href=#when-t-is-tomlvaluesome_type>When <code>T</code> is <code>toml::value::{some_type}</code></a></li><li><a href=#when-t-is-const-char>When <code>T</code> is <code>const char*</code></a></li><li><a href=#when-t-is-any-other-type>When <code>T</code> is any other type</a></li><li><a href=#when-multiple-keys-are-provided>When multiple keys are provided</a></li></ul></li><li><a href=#related>Related</a></li></ul></nav></div></aside></main></body></html>