Provide C++20-style operator| to filter iterator ranges. #12952
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In the same spirit as provided by the C++20 range adaptors feature, this little function makes it possible to "filter" ranges over the active cells of Triangulation and DoFHandler objects.
This allows to replace:
by:
Here, the
operator|
is to be interpreted in the same way as is done in the range adaptors feature that is part of C++20. It hasthe same meaning as the
|
symbol on the command line: It takes what is on its left as its inputs, and filters and transforms to produce some output. In the example above, it "filters" all of the active cell iterators and removes those that do not satisfy the predicate -- that is, it produces a range of iterators that only contains those cells that are both active and locally owned.I've wanted to do this for a long time because the syntax of range adaptors (of which filters are a special case) is so elegant. It turns out that if one looks at what we already have, it was all there: We just had it in a free function
filter_iterators()
, rather than anoperator|()
.The last commit here converts a few random places to see whether this all actually works :-)
/rebuild