From 7c66cf7b06c322edfa3811021f915da0041fec0a Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sun, 19 May 2024 13:24:34 -0700 Subject: [PATCH] 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. --- docs/manual.adoc | 14 +++++++++++++- docs/manual.html | 18 ++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/docs/manual.adoc b/docs/manual.adoc index 45b2f3c9..70436e81 100644 --- a/docs/manual.adoc +++ b/docs/manual.adoc @@ -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]] diff --git a/docs/manual.html b/docs/manual.html index 05399677..04c56e81 100644 --- a/docs/manual.html +++ b/docs/manual.html @@ -448,6 +448,7 @@ 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 @@

-
for (pugi::xml_node child: tool)
+
for (pugi::xml_node child: tool) ...
+
+
+
+

When using C++20, you can also use nodes as well as objects returned by children() and attributes() functions as ranges:

+
+
+
+
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) ...
@@ -6153,7 +6167,7 @@