From 2b8a59e2e1093ab88c440b47f1a901d3adbf653b Mon Sep 17 00:00:00 2001 From: Max Lyon Date: Fri, 22 Nov 2019 11:02:31 +0100 Subject: [PATCH 1/2] add method that converts smart range to set --- src/OpenMesh/Core/Mesh/SmartRange.hh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/OpenMesh/Core/Mesh/SmartRange.hh b/src/OpenMesh/Core/Mesh/SmartRange.hh index a2405a68..9f9825af 100644 --- a/src/OpenMesh/Core/Mesh/SmartRange.hh +++ b/src/OpenMesh/Core/Mesh/SmartRange.hh @@ -45,6 +45,7 @@ #include #include #include +#include //== NAMESPACES =============================================================== @@ -189,6 +190,23 @@ struct SmartRangeT return res; } + /** @brief Convert range to set. + * + * Converts the range of elements into a set of objects returned by functor \p f. + * + * @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 to_set(Functor&& f = {}) -> std::set()))>::type> + { + auto range = static_cast(this); + std::set()))>::type> res; + for (const auto& e : *range) + res.insert(f(e)); + return res; + } + /** @brief Compute minimum. * * Computes the minimum of all objects returned by functor \p f. From 65cafaf17ca6dde5e0063f27ece753abe605196a Mon Sep 17 00:00:00 2001 From: Max Lyon Date: Fri, 22 Nov 2019 11:02:50 +0100 Subject: [PATCH 2/2] add method that returns first element of a smart range that fulfills a condition --- src/OpenMesh/Core/Mesh/SmartRange.hh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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.