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,197 @@
<!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="
parser.hpp
#
Defines functions for parsing files or strings and the exceptions they use.
While parse throws an exception on failure, try_parse returns error information.
parse
#
Parses the content of a given file and returns a toml::basic_value.
In case of failure, toml::syntax_error is thrown.
The type information of basic_value is provided by a template, and the TOML language version is specified by toml::spec.
parse(std::string filename, toml::spec)
#
namespace toml
{
template<typename TC = type_config>
basic_value<TC>
parse(std::string fname,
spec s = spec::default_version());
}
Parses the content of the given filename."><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/parser/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="parser.hpp"><meta property="og:description" content="parser.hpp # Defines functions for parsing files or strings and the exceptions they use.
While parse throws an exception on failure, try_parse returns error information.
parse # Parses the content of a given file and returns a toml::basic_value.
In case of failure, toml::syntax_error is thrown.
The type information of basic_value is provided by a template, and the TOML language version is specified by toml::spec.
parse(std::string filename, toml::spec) # namespace toml { template<typename TC = type_config> basic_value<TC> parse(std::string fname, spec s = spec::default_version()); } Parses the content of the given filename."><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>parser.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/parser/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/reference/parser/ title=parser.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/parser/>日本語</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/>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/ class=active>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>parser.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=#parserhpp>parser.hpp</a></li><li><a href=#parse><code>parse</code></a><ul><li><ul><li><a href=#parsestdstring-filename-tomlspec><code>parse(std::string filename, toml::spec)</code></a></li><li><a href=#parseconst-char-n-filename-tomlspec><code>parse(const char (&)[N] filename, toml::spec)</code></a></li><li><a href=#parsestdfilesystempath-tomlspec><code>parse(std::filesystem::path, toml::spec)</code></a></li><li><a href=#parsestdistream-stdstring-filename-tomlspec><code>parse(std::istream&, std::string filename, toml::spec)</code></a></li><li><a href=#parsefile-stdstring-filename-tomlspec><code>parse(FILE*, std::string filename, toml::spec)</code></a></li><li><a href=#parsestdvectorunsigned-char-stdstring-filename-tomlspec><code>parse(std::vector&lt;unsigned char>, std::string filename, toml::spec)</code></a></li></ul></li></ul></li><li><a href=#parse_str><code>parse_str</code></a><ul><li><ul><li><a href=#parse_strstdstring-tomlspec><code>parse_str(std::string, toml::spec)</code></a></li></ul></li></ul></li><li><a href=#try_parse><code>try_parse</code></a><ul><li><ul><li><a href=#try_parsestdstring-filename-tomlspec><code>try_parse(std::string filename, toml::spec)</code></a></li><li><a href=#try_parseconst-char-n-filename-tomlspec><code>try_parse(const char (&)[N] filename, toml::spec)</code></a></li><li><a href=#try_parsestdfilesystempath-tomlspec><code>try_parse(std::filesystem::path, toml::spec)</code></a></li><li><a href=#try_parsestdistream-stdstring-filename-tomlspec><code>try_parse(std::istream&, std::string filename, toml::spec)</code></a></li><li><a href=#try_parsefile-stdstring-filename-tomlspec><code>try_parse(FILE*, std::string filename, toml::spec)</code></a></li><li><a href=#try_parsestdvectorunsigned-char-stdstring-filename-tomlspec><code>try_parse(std::vector&lt;unsigned char>, std::string filename, toml::spec)</code></a></li></ul></li></ul></li><li><a href=#try_parse_str><code>try_parse_str</code></a><ul><li><ul><li><a href=#try_parse_strstdstring-tomlspec><code>try_parse_str(std::string, toml::spec)</code></a></li></ul></li></ul></li><li><a href=#syntax_error><code>syntax_error</code></a></li><li><a href=#file_io_error><code>file_io_error</code></a><ul><li><ul><li><a href=#has_errno><code>has_errno</code></a></li><li><a href=#get_errno><code>get_errno</code></a></li></ul></li></ul></li><li><a href=#related>Related</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=parserhpp>parser.hpp
<a class=anchor href=#parserhpp>#</a></h1><p>Defines functions for parsing files or strings and the exceptions they use.</p><p>While <code>parse</code> throws an exception on failure, <code>try_parse</code> returns error information.</p><h1 id=parse><code>parse</code>
<a class=anchor href=#parse>#</a></h1><p>Parses the content of a given file and returns a <code>toml::basic_value</code>.</p><p>In case of failure, <code>toml::syntax_error</code> is thrown.</p><p>The type information of <code>basic_value</code> is provided by a <code>template</code>, and the TOML language version is specified by <code>toml::spec</code>.</p><h3 id=parsestdstring-filename-tomlspec><code>parse(std::string filename, toml::spec)</code>
<a class=anchor href=#parsestdstring-filename-tomlspec>#</a></h3><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>namespace</span> toml
</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>=</span> type_config<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></span><span style=display:flex><span>parse(std<span style=color:#f92672>::</span>string fname,
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version());
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><p>Parses the content of the given filename.</p><p>If reading the file fails, <code>toml::file_io_error</code> is thrown.</p><p>If parsing fails, <code>toml::syntax_error</code> is thrown.</p><h3 id=parseconst-char-n-filename-tomlspec><code>parse(const char (&)[N] filename, toml::spec)</code>
<a class=anchor href=#parseconst-char-n-filename-tomlspec>#</a></h3><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>namespace</span> toml
</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>=</span> type_config, std<span style=color:#f92672>::</span>size_t N<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></span><span style=display:flex><span>parse(<span style=color:#66d9ef>const</span> <span style=color:#66d9ef>char</span> (<span style=color:#f92672>&amp;</span>fname)[N],
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version());
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><p>Parses the content of the given filename from a string literal.</p><p>If reading the file fails, <code>toml::file_io_error</code> is thrown.</p><p>If parsing fails, <code>toml::syntax_error</code> is thrown.</p><h3 id=parsestdfilesystempath-tomlspec><code>parse(std::filesystem::path, toml::spec)</code>
<a class=anchor href=#parsestdfilesystempath-tomlspec>#</a></h3><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>namespace</span> toml
</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>=</span> type_config<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></span><span style=display:flex><span>parse(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>filesystem<span style=color:#f92672>::</span>path<span style=color:#f92672>&amp;</span> fpath,
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version());
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><p>This is defined only if <code>&lt;filesystem></code> is available.</p><p>Parses the content of the file at the given file path.</p><p>If reading the file fails, <code>toml::file_io_error</code> is thrown.</p><p>If parsing fails, <code>toml::syntax_error</code> is thrown.</p><h3 id=parsestdistream-stdstring-filename-tomlspec><code>parse(std::istream&, std::string filename, toml::spec)</code>
<a class=anchor href=#parsestdistream-stdstring-filename-tomlspec>#</a></h3><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>namespace</span> toml
</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>=</span> type_config<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></span><span style=display:flex><span>parse(std<span style=color:#f92672>::</span>istream<span style=color:#f92672>&amp;</span> is,
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string fname <span style=color:#f92672>=</span> <span style=color:#e6db74>&#34;unknown file&#34;</span>,
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version());
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><p>Parses the content of the given <code>std::istream&</code>.</p><p>Open a stream in binary mode by passing <code>std::ios::binary</code> to avoid inconsistency between the file size and the number of characters due to automatic conversion of newline characters by the standard library.</p><p>The filename information is taken as the second argument. If the filename is not provided, it defaults to <code>"unknown file"</code>.</p><h3 id=parsefile-stdstring-filename-tomlspec><code>parse(FILE*, std::string filename, toml::spec)</code>
<a class=anchor href=#parsefile-stdstring-filename-tomlspec>#</a></h3><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>namespace</span> toml
</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>=</span> type_config<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span>result<span style=color:#f92672>&lt;</span>basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;</span>, std<span style=color:#f92672>::</span>vector<span style=color:#f92672>&lt;</span>error_info<span style=color:#f92672>&gt;&gt;</span>
</span></span><span style=display:flex><span>parse(FILE<span style=color:#f92672>*</span> fp,
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string filename,
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version());
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><p>Parses the content of the file pointed to by <code>FILE*</code>.</p><p>Open a stream in binary mode by passing <code>"rb"</code> to avoid inconsistency between the file size and the number of characters due to automatic conversion of newline characters by the standard library.</p><p>If reading the file fails, <code>file_io_error</code> containing <code>errno</code> is thrown.</p><p>If parsing fails, <code>syntax_error</code> is thrown.</p><h3 id=parsestdvectorunsigned-char-stdstring-filename-tomlspec><code>parse(std::vector&lt;unsigned char>, std::string filename, toml::spec)</code>
<a class=anchor href=#parsestdvectorunsigned-char-stdstring-filename-tomlspec>#</a></h3><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>namespace</span> toml
</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>=</span> type_config<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></span><span style=display:flex><span>parse(std<span style=color:#f92672>::</span>vector<span style=color:#f92672>&lt;</span><span style=color:#66d9ef>unsigned</span> <span style=color:#66d9ef>char</span><span style=color:#f92672>&gt;</span> content,
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string filename,
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version());
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><p>Parses the byte sequence as a TOML file.</p><p>If parsing fails, <code>toml::syntax_error</code> is thrown.</p><h1 id=parse_str><code>parse_str</code>
<a class=anchor href=#parse_str>#</a></h1><h3 id=parse_strstdstring-tomlspec><code>parse_str(std::string, toml::spec)</code>
<a class=anchor href=#parse_strstdstring-tomlspec>#</a></h3><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>namespace</span> toml
</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>=</span> type_config<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></span><span style=display:flex><span>parse_str(std<span style=color:#f92672>::</span>string content,
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version(),
</span></span><span style=display:flex><span> cxx<span style=color:#f92672>::</span>source_location loc <span style=color:#f92672>=</span> cxx<span style=color:#f92672>::</span>source_location<span style=color:#f92672>::</span>current());
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><p>Parses a string as a TOML file.</p><p>In case of failure, <code>toml::syntax_error</code> is thrown.</p><p>The type information of <code>basic_value</code> is provided by a <code>template</code>, and the TOML language version is specified by <code>toml::spec</code>.</p><p>You generally don&rsquo;t need to manually set the third argument, <code>cxx::source_location</code>.
If <code>std::source_location</code>, <code>std::experimental::source_location</code>, or <code>__builtin_FILE</code> is available,
the location information where <code>parse_str</code> was called will be stored.</p><h1 id=try_parse><code>try_parse</code>
<a class=anchor href=#try_parse>#</a></h1><p>Parses the contents of the given file and returns a <code>toml::basic_value</code> if successful, or a <code>std::vector&lt;toml::error_info></code> if it fails.</p><p>The type information of <code>basic_value</code> is specified by <code>template</code>, and the version of the TOML language is specified by <code>toml::spec</code>.</p><blockquote class="book-hint warning"><p>Unlike <code>parse</code>, <code>try_parse</code> does not throw exceptions defined in toml11 such as <code>syntax_error</code>.
However, please note that exceptions thrown by the standard library will still propagate.</p><p>For instance, errors occurring internally within <code>std::ifstream</code> or memory exhaustion in <code>std::vector</code> will throw exceptions.</p></blockquote><h3 id=try_parsestdstring-filename-tomlspec><code>try_parse(std::string filename, toml::spec)</code>
<a class=anchor href=#try_parsestdstring-filename-tomlspec>#</a></h3><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>namespace</span> toml
</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>=</span> type_config<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span>result<span style=color:#f92672>&lt;</span>basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;</span>, std<span style=color:#f92672>::</span>vector<span style=color:#f92672>&lt;</span>error_info<span style=color:#f92672>&gt;&gt;</span>
</span></span><span style=display:flex><span>try_parse(std<span style=color:#f92672>::</span>string fname,
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version());
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><p>Takes a file name and parses its content.</p><p>If parsing fails, a <code>result</code> holding the error type <code>std::vector&lt;error_info></code> is returned.</p><p>If successful, a <code>result</code> holding a <code>basic_value</code> is returned.</p><h3 id=try_parseconst-char-n-filename-tomlspec><code>try_parse(const char (&)[N] filename, toml::spec)</code>
<a class=anchor href=#try_parseconst-char-n-filename-tomlspec>#</a></h3><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>namespace</span> toml
</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>=</span> type_config, std<span style=color:#f92672>::</span>size_t N<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span>result<span style=color:#f92672>&lt;</span>basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;</span>, std<span style=color:#f92672>::</span>vector<span style=color:#f92672>&lt;</span>error_info<span style=color:#f92672>&gt;&gt;</span>
</span></span><span style=display:flex><span>try_parse(<span style=color:#66d9ef>const</span> <span style=color:#66d9ef>char</span> (<span style=color:#f92672>&amp;</span>fname)[N],
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version());
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><p>Takes a string literal as a file name and parses its content.</p><p>If parsing fails, a <code>result</code> holding the error type <code>std::vector&lt;error_info></code> is returned.</p><p>If successful, a <code>result</code> holding a <code>basic_value</code> is returned.</p><h3 id=try_parsestdfilesystempath-tomlspec><code>try_parse(std::filesystem::path, toml::spec)</code>
<a class=anchor href=#try_parsestdfilesystempath-tomlspec>#</a></h3><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>namespace</span> toml
</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>=</span> type_config<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span>result<span style=color:#f92672>&lt;</span>basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;</span>, std<span style=color:#f92672>::</span>vector<span style=color:#f92672>&lt;</span>error_info<span style=color:#f92672>&gt;&gt;</span>
</span></span><span style=display:flex><span>try_parse(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>filesystem<span style=color:#f92672>::</span>path<span style=color:#f92672>&amp;</span> fpath,
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version());
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><p>Takes a file path and parses its content.</p><p>If parsing fails, a <code>result</code> holding the error type <code>std::vector&lt;error_info></code> is returned.</p><p>If successful, a <code>result</code> holding a <code>basic_value</code> is returned.</p><h3 id=try_parsestdistream-stdstring-filename-tomlspec><code>try_parse(std::istream&, std::string filename, toml::spec)</code>
<a class=anchor href=#try_parsestdistream-stdstring-filename-tomlspec>#</a></h3><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>namespace</span> toml
</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>=</span> type_config<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span>result<span style=color:#f92672>&lt;</span>basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;</span>, std<span style=color:#f92672>::</span>vector<span style=color:#f92672>&lt;</span>error_info<span style=color:#f92672>&gt;&gt;</span>
</span></span><span style=display:flex><span>try_parse(std<span style=color:#f92672>::</span>istream<span style=color:#f92672>&amp;</span> is,
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string fname <span style=color:#f92672>=</span> <span style=color:#e6db74>&#34;unknown file&#34;</span>,
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version());
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><p>Takes a <code>std::istream&</code> and parses its content.</p><p>Open a stream in binary mode by passing <code>std::ios::binary</code> to avoid inconsistency between the file size and the number of characters due to automatic conversion of newline characters by the standard library.</p><p>The file name information is taken as the second argument. If a file name is not provided, it defaults to <code>"unknown file"</code>.</p><p>If parsing fails, a <code>result</code> holding the error type <code>std::vector&lt;error_info></code> is returned.</p><p>If successful, a <code>result</code> holding a <code>basic_value</code> is returned.</p><h3 id=try_parsefile-stdstring-filename-tomlspec><code>try_parse(FILE*, std::string filename, toml::spec)</code>
<a class=anchor href=#try_parsefile-stdstring-filename-tomlspec>#</a></h3><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>namespace</span> toml
</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>=</span> type_config<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span>result<span style=color:#f92672>&lt;</span>basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;</span>, std<span style=color:#f92672>::</span>vector<span style=color:#f92672>&lt;</span>error_info<span style=color:#f92672>&gt;&gt;</span>
</span></span><span style=display:flex><span>try_parse(FILE<span style=color:#f92672>*</span> fp,
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string filename,
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version());
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><p>Takes a <code>FILE*</code> and parses its content.</p><p>Open a stream in binary mode by passing <code>"rb"</code> to avoid inconsistency between the file size and the number of characters due to automatic conversion of newline characters by the standard library.</p><p>If parsing fails, a <code>result</code> holding the error type <code>std::vector&lt;error_info></code> is returned.</p><p>If successful, a <code>result</code> holding a <code>basic_value</code> is returned.</p><h3 id=try_parsestdvectorunsigned-char-stdstring-filename-tomlspec><code>try_parse(std::vector&lt;unsigned char>, std::string filename, toml::spec)</code>
<a class=anchor href=#try_parsestdvectorunsigned-char-stdstring-filename-tomlspec>#</a></h3><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>namespace</span> toml
</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>=</span> type_config<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span>result<span style=color:#f92672>&lt;</span>basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;</span>, std<span style=color:#f92672>::</span>vector<span style=color:#f92672>&lt;</span>error_info<span style=color:#f92672>&gt;&gt;</span>
</span></span><span style=display:flex><span>try_parse(std<span style=color:#f92672>::</span>vector<span style=color:#f92672>&lt;</span><span style=color:#66d9ef>unsigned</span> <span style=color:#66d9ef>char</span><span style=color:#f92672>&gt;</span> content,
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string filename,
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version());
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><p>Takes a byte array and parses its content as a TOML file.</p><p>If parsing fails, a <code>result</code> holding the error type <code>std::vector&lt;error_info></code> is returned.</p><p>If successful, a <code>result</code> holding a <code>basic_value</code> is returned.</p><h1 id=try_parse_str><code>try_parse_str</code>
<a class=anchor href=#try_parse_str>#</a></h1><h3 id=try_parse_strstdstring-tomlspec><code>try_parse_str(std::string, toml::spec)</code>
<a class=anchor href=#try_parse_strstdstring-tomlspec>#</a></h3><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>namespace</span> toml
</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>=</span> type_config<span style=color:#f92672>&gt;</span>
</span></span><span style=display:flex><span>result<span style=color:#f92672>&lt;</span>basic_value<span style=color:#f92672>&lt;</span>TC<span style=color:#f92672>&gt;</span>, std<span style=color:#f92672>::</span>vector<span style=color:#f92672>&lt;</span>error_info<span style=color:#f92672>&gt;&gt;</span>
</span></span><span style=display:flex><span>try_parse_str(std<span style=color:#f92672>::</span>string content,
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version(),
</span></span><span style=display:flex><span> cxx<span style=color:#f92672>::</span>source_location loc <span style=color:#f92672>=</span> cxx<span style=color:#f92672>::</span>source_location<span style=color:#f92672>::</span>current());
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><p>Parses a string as a TOML file, returning a <code>toml::basic_value</code> if successful, or a <code>std::vector&lt;toml::error_info></code> if it fails.</p><p>Unlike <code>parse_str</code>, it does not throw <code>syntax_error</code>, but instead returns error information as the failure type of the <code>result</code>.</p><p>If <code>std::source_location</code>, <code>std::experimental::source_location</code>, or <code>__builtin_FILE</code> is available, it will record the location information.</p><p>Typically, you do not need to manually set the third argument <code>cxx::source_location</code>. If any of <code>std::source_location</code>, <code>std::experimental::source_location</code>, or <code>__builtin_FILE</code> are available, the information of the location where <code>parse_str</code> was called will be saved as the location information.</p><blockquote class="book-hint warning"><p>Unlike <code>parse</code>, <code>try_parse</code> does not throw exceptions defined in toml11 such as <code>syntax_error</code>. However, please note that exceptions thrown by the standard library will still propagate.</p><p>For instance, errors occurring internally within <code>std::ifstream</code> or memory exhaustion in <code>std::vector</code> will throw exceptions.</p></blockquote><h1 id=syntax_error><code>syntax_error</code>
<a class=anchor href=#syntax_error>#</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>namespace</span> toml
</span></span><span style=display:flex><span>{
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>syntax_error</span> <span style=color:#66d9ef>final</span> <span style=color:#f92672>:</span> <span style=color:#66d9ef>public</span> <span style=color:#f92672>::</span>toml<span style=color:#f92672>::</span>exception
</span></span><span style=display:flex><span>{
</span></span><span style=display:flex><span> <span style=color:#66d9ef>public</span><span style=color:#f92672>:</span>
</span></span><span style=display:flex><span> syntax_error(std<span style=color:#f92672>::</span>string what_arg, std<span style=color:#f92672>::</span>vector<span style=color:#f92672>&lt;</span>error_info<span style=color:#f92672>&gt;</span> err);
</span></span><span style=display:flex><span> <span style=color:#f92672>~</span>syntax_error() <span style=color:#66d9ef>noexcept</span> <span style=color:#66d9ef>override</span> <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>char</span><span style=color:#f92672>*</span> <span style=color:#a6e22e>what</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span> <span style=color:#66d9ef>override</span>;
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>vector<span style=color:#f92672>&lt;</span>error_info<span style=color:#f92672>&gt;</span> <span style=color:#66d9ef>const</span><span style=color:#f92672>&amp;</span> errors() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>
</span></span><span style=display:flex><span>};
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><p>An exception thrown when a syntax error is detected in TOML.</p><p>It is thrown by <code>parse</code> but not by <code>try_parse</code>.</p><h1 id=file_io_error><code>file_io_error</code>
<a class=anchor href=#file_io_error>#</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>namespace</span> toml
</span></span><span style=display:flex><span>{
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>file_io_error</span> <span style=color:#66d9ef>final</span> <span style=color:#f92672>:</span> <span style=color:#66d9ef>public</span> <span style=color:#f92672>::</span>toml<span style=color:#f92672>::</span>exception
</span></span><span style=display:flex><span>{
</span></span><span style=display:flex><span> <span style=color:#66d9ef>public</span><span style=color:#f92672>:</span>
</span></span><span style=display:flex><span> file_io_error(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&amp;</span> msg, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&amp;</span> fname);
</span></span><span style=display:flex><span> file_io_error(<span style=color:#66d9ef>int</span> errnum, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&amp;</span> msg, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&amp;</span> fname);
</span></span><span style=display:flex><span> <span style=color:#f92672>~</span>file_io_error() <span style=color:#66d9ef>noexcept</span> <span style=color:#66d9ef>override</span> <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>char</span><span style=color:#f92672>*</span> <span style=color:#a6e22e>what</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span> <span style=color:#66d9ef>override</span>;
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span> <span style=color:#66d9ef>bool</span> <span style=color:#a6e22e>has_errno</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
</span></span><span style=display:flex><span> <span style=color:#66d9ef>int</span> <span style=color:#a6e22e>get_errno</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
</span></span><span style=display:flex><span>};
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><p>An exception thrown when reading the contents of a file fails.</p><p>When using <code>FILE*</code> to read a file, <code>errno</code> is set.</p><h3 id=has_errno><code>has_errno</code>
<a class=anchor href=#has_errno>#</a></h3><p>If <code>std::ifstream</code> fails, <code>errno</code> is not set.</p><p>In this case, <code>has_errno</code> returns <code>false</code>.</p><h3 id=get_errno><code>get_errno</code>
<a class=anchor href=#get_errno>#</a></h3><p>Particularly when passing a <code>FILE*</code>, retrieves the value of <code>errno</code>.</p><p>If <code>has_errno</code> is <code>false</code>, it returns <code>0</code>.</p><h1 id=related>Related
<a class=anchor href=#related>#</a></h1><ul><li><a href=https://toruniina.github.io/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=https://toruniina.github.io/toml11/docs/reference/result/>result.hpp</a></li><li><a href=https://toruniina.github.io/toml11/docs/reference/spec/>spec.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=#parserhpp>parser.hpp</a></li><li><a href=#parse><code>parse</code></a><ul><li><ul><li><a href=#parsestdstring-filename-tomlspec><code>parse(std::string filename, toml::spec)</code></a></li><li><a href=#parseconst-char-n-filename-tomlspec><code>parse(const char (&)[N] filename, toml::spec)</code></a></li><li><a href=#parsestdfilesystempath-tomlspec><code>parse(std::filesystem::path, toml::spec)</code></a></li><li><a href=#parsestdistream-stdstring-filename-tomlspec><code>parse(std::istream&, std::string filename, toml::spec)</code></a></li><li><a href=#parsefile-stdstring-filename-tomlspec><code>parse(FILE*, std::string filename, toml::spec)</code></a></li><li><a href=#parsestdvectorunsigned-char-stdstring-filename-tomlspec><code>parse(std::vector&lt;unsigned char>, std::string filename, toml::spec)</code></a></li></ul></li></ul></li><li><a href=#parse_str><code>parse_str</code></a><ul><li><ul><li><a href=#parse_strstdstring-tomlspec><code>parse_str(std::string, toml::spec)</code></a></li></ul></li></ul></li><li><a href=#try_parse><code>try_parse</code></a><ul><li><ul><li><a href=#try_parsestdstring-filename-tomlspec><code>try_parse(std::string filename, toml::spec)</code></a></li><li><a href=#try_parseconst-char-n-filename-tomlspec><code>try_parse(const char (&)[N] filename, toml::spec)</code></a></li><li><a href=#try_parsestdfilesystempath-tomlspec><code>try_parse(std::filesystem::path, toml::spec)</code></a></li><li><a href=#try_parsestdistream-stdstring-filename-tomlspec><code>try_parse(std::istream&, std::string filename, toml::spec)</code></a></li><li><a href=#try_parsefile-stdstring-filename-tomlspec><code>try_parse(FILE*, std::string filename, toml::spec)</code></a></li><li><a href=#try_parsestdvectorunsigned-char-stdstring-filename-tomlspec><code>try_parse(std::vector&lt;unsigned char>, std::string filename, toml::spec)</code></a></li></ul></li></ul></li><li><a href=#try_parse_str><code>try_parse_str</code></a><ul><li><ul><li><a href=#try_parse_strstdstring-tomlspec><code>try_parse_str(std::string, toml::spec)</code></a></li></ul></li></ul></li><li><a href=#syntax_error><code>syntax_error</code></a></li><li><a href=#file_io_error><code>file_io_error</code></a><ul><li><ul><li><a href=#has_errno><code>has_errno</code></a></li><li><a href=#get_errno><code>get_errno</code></a></li></ul></li></ul></li><li><a href=#related>Related</a></li></ul></nav></div></aside></main></body></html>