From 4e40352a5fdc16256f7bdd928db745a360297edb Mon Sep 17 00:00:00 2001 From: Max Lyon Date: Wed, 6 May 2020 10:45:41 +0200 Subject: [PATCH] add filtered range that stores reference instead of copy if the filter is not an rvalue reference --- src/OpenMesh/Core/Mesh/SmartRange.hh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/OpenMesh/Core/Mesh/SmartRange.hh b/src/OpenMesh/Core/Mesh/SmartRange.hh index 04053153..09db60c6 100644 --- a/src/OpenMesh/Core/Mesh/SmartRange.hh +++ b/src/OpenMesh/Core/Mesh/SmartRange.hh @@ -408,6 +408,20 @@ struct SmartRangeT return FilteredSmartRangeT::type>(f, b, e); } + /** @brief Only iterate over a subset of elements + * + * Returns a smart range which skips all elements that do not satisfy functor \p f + * + * @param f Functor that needs to be evaluated to true if the element should not be skipped. + */ + template + auto filtered(Functor& f) -> FilteredSmartRangeT::type&> + { + auto range = static_cast(this); + auto b = (*range).begin(); + auto e = (*range).end(); + return FilteredSmartRangeT::type&>(f, b, e); + } };