Closed davidhunter22 closed 5 months ago
Oh I forgot to add, a traversal of all elements would look like
std::generator<pugi::xml_node> traverse_gen( pugi::xml_node node )
{
co_yield node;
for( auto child : node )
{
co_yield std::ranges::elements_of( traverse_gen( child ) );
}
}
This is a side effect of ranged for support (https://pugixml.org/docs/manual.html#access.rangefor); accordingly, you can treat objects returned by .children()
, .children(name)
and .attributes()
as ranges as well.
I'll adjust the documentation linked above to mention this; it might eventually make sense to add a separate documentation section but for now I can't even use std::ranges::to
on clang/gcc provided by Ubuntu 24.04 which released last month as their C++23 support is incomplete.
I see a number of comments about traversal and iteration of element in pugixml. So this is more an observation which I think should be in the documentation and I'm not sure most people realize. The following
Is true! I am of course assuming that this is by design, but it may not be obvious to people what the implications are. This means that nodes and less usefully attributes are ranges and can be used as ranges. So
should work. We use "node as ranges" a lot and it greatly simplifies our code.
For another example consider the following. This creates a range of siblings using next_sibling which is not a range