diff --git a/src/OpenMesh/Core/Mesh/SmartRange.hh b/src/OpenMesh/Core/Mesh/SmartRange.hh index 9f9825af..24b12f39 100644 --- a/src/OpenMesh/Core/Mesh/SmartRange.hh +++ b/src/OpenMesh/Core/Mesh/SmartRange.hh @@ -207,6 +207,24 @@ struct SmartRangeT return res; } + /** @brief Get the first element that fulfills a condition. + * + * Finds the first element of the range for which the functor \p f evaluates to true. + * Returns an invalid handle if none evaluates to true + * + * @param f Functor that is applied to all elements before putting them into the set. If no functor is provided + * the set will contain the handles. + */ + template + auto first(Functor&& f = {}) -> HandleT + { + auto range = static_cast(this); + for (const auto& e : *range) + if (f(e)) + return e; + return HandleT(); + } + /** @brief Compute minimum. * * Computes the minimum of all objects returned by functor \p f.