mirror of
https://github.com/zeux/pugixml.git
synced 2024-12-26 12:41:06 +08:00
docs: Add C++20 ranges documentation
This doesn't require any implementation changes, as the existing support for C++11 ranged for loops automatically makes nodes and node/attribute range objects work as C++20 ranges. Fixes #613.
This commit is contained in:
parent
f1d8c51ec8
commit
7c66cf7b06
@ -1039,7 +1039,19 @@ While using `children()` makes the intent of the code clear, note that each node
|
||||
|
||||
[source]
|
||||
----
|
||||
for (pugi::xml_node child: tool)
|
||||
for (pugi::xml_node child: tool) ...
|
||||
----
|
||||
|
||||
When using C{plus}{plus}20, you can also use nodes as well as objects returned by `children()` and `attributes()` functions as ranges:
|
||||
|
||||
[source]
|
||||
----
|
||||
auto tf =
|
||||
tools.children("Tool")
|
||||
| std::views::filter([](auto node) { return node.attribute("AllowRemote").as_bool(); })
|
||||
| std::views::reverse;
|
||||
|
||||
for (pugi::xml_node tool: tf) ...
|
||||
----
|
||||
|
||||
[[access.iterators]]
|
||||
|
@ -448,6 +448,7 @@ pre.pygments .tok-c1 { color: #3D7B7B; font-style: italic } /* Comment.Single */
|
||||
pre.pygments .tok-cs { color: #3D7B7B; font-style: italic } /* Comment.Special */
|
||||
pre.pygments .tok-gd { color: #A00000 } /* Generic.Deleted */
|
||||
pre.pygments .tok-ge { font-style: italic } /* Generic.Emph */
|
||||
pre.pygments .tok-ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
|
||||
pre.pygments .tok-gr { color: #E40000 } /* Generic.Error */
|
||||
pre.pygments .tok-gh { color: #000080; font-weight: bold } /* Generic.Heading */
|
||||
pre.pygments .tok-gi { color: #008400 } /* Generic.Inserted */
|
||||
@ -2300,7 +2301,20 @@ If your C++ compiler supports range-based for-loop (this is a C++
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre class="pygments highlight"><code data-lang="c++"><span></span><span class="tok-k">for</span><span class="tok-w"> </span><span class="tok-p">(</span><span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xml_node</span><span class="tok-w"> </span><span class="tok-n">child</span><span class="tok-o">:</span><span class="tok-w"> </span><span class="tok-n">tool</span><span class="tok-p">)</span></code></pre>
|
||||
<pre class="pygments highlight"><code data-lang="c++"><span></span><span class="tok-k">for</span><span class="tok-w"> </span><span class="tok-p">(</span><span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xml_node</span><span class="tok-w"> </span><span class="tok-n">child</span><span class="tok-o">:</span><span class="tok-w"> </span><span class="tok-n">tool</span><span class="tok-p">)</span><span class="tok-w"> </span><span class="tok-p">...</span></code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>When using C++20, you can also use nodes as well as objects returned by <code>children()</code> and <code>attributes()</code> functions as ranges:</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre class="pygments highlight"><code data-lang="c++"><span></span><span class="tok-k">auto</span><span class="tok-w"> </span><span class="tok-n">tf</span><span class="tok-w"> </span><span class="tok-o">=</span>
|
||||
<span class="tok-w"> </span><span class="tok-n">tools</span><span class="tok-p">.</span><span class="tok-n">children</span><span class="tok-p">(</span><span class="tok-s">"Tool"</span><span class="tok-p">)</span>
|
||||
<span class="tok-w"> </span><span class="tok-o">|</span><span class="tok-w"> </span><span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">views</span><span class="tok-o">::</span><span class="tok-n">filter</span><span class="tok-p">([](</span><span class="tok-k">auto</span><span class="tok-w"> </span><span class="tok-n">node</span><span class="tok-p">)</span><span class="tok-w"> </span><span class="tok-p">{</span><span class="tok-w"> </span><span class="tok-k">return</span><span class="tok-w"> </span><span class="tok-n">node</span><span class="tok-p">.</span><span class="tok-n">attribute</span><span class="tok-p">(</span><span class="tok-s">"AllowRemote"</span><span class="tok-p">).</span><span class="tok-n">as_bool</span><span class="tok-p">();</span><span class="tok-w"> </span><span class="tok-p">})</span>
|
||||
<span class="tok-w"> </span><span class="tok-o">|</span><span class="tok-w"> </span><span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">views</span><span class="tok-o">::</span><span class="tok-n">reverse</span><span class="tok-p">;</span>
|
||||
|
||||
<span class="tok-k">for</span><span class="tok-w"> </span><span class="tok-p">(</span><span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xml_node</span><span class="tok-w"> </span><span class="tok-n">tool</span><span class="tok-o">:</span><span class="tok-w"> </span><span class="tok-n">tf</span><span class="tok-p">)</span><span class="tok-w"> </span><span class="tok-p">...</span></code></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -6153,7 +6167,7 @@ If exceptions are disabled, then in the event of parsing failure the query is in
|
||||
</div>
|
||||
<div id="footer">
|
||||
<div id="footer-text">
|
||||
Last updated 2024-01-26 09:23:09 -0800
|
||||
Last updated 2024-05-19 13:23:06 -0700
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
Loading…
x
Reference in New Issue
Block a user