From 04e798920d57cc9117187e41cfe4dcc1567c48f1 Mon Sep 17 00:00:00 2001 From: Max Lyon Date: Thu, 28 Nov 2019 11:49:37 +0100 Subject: [PATCH 1/4] use decay instead of remove_reference to also remove constness in SmartRanges --- src/OpenMesh/Core/Mesh/SmartRange.hh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/OpenMesh/Core/Mesh/SmartRange.hh b/src/OpenMesh/Core/Mesh/SmartRange.hh index 24b12f39..5f925e0d 100644 --- a/src/OpenMesh/Core/Mesh/SmartRange.hh +++ b/src/OpenMesh/Core/Mesh/SmartRange.hh @@ -161,10 +161,10 @@ struct SmartRangeT * the array will contain the handles. */ template - auto to_array(Functor&& f = {}) -> std::array()))>::type, n> + auto to_array(Functor&& f = {}) -> std::array()))>::type, n> { auto range = static_cast(this); - std::array()))>::type, n> res; + std::array()))>::type, n> res; auto it = range->begin(); auto end = range->end(); int i = 0; @@ -181,10 +181,10 @@ struct SmartRangeT * the vector will contain the handles. */ template - auto to_vector(Functor&& f = {}) -> std::vector()))>::type> + auto to_vector(Functor&& f = {}) -> std::vector()))>::type> { auto range = static_cast(this); - std::vector()))>::type> res; + std::vector()))>::type> res; for (const auto& e : *range) res.push_back(f(e)); return res; @@ -198,10 +198,10 @@ struct SmartRangeT * the set will contain the handles. */ template - auto to_set(Functor&& f = {}) -> std::set()))>::type> + auto to_set(Functor&& f = {}) -> std::set()))>::type> { auto range = static_cast(this); - std::set()))>::type> res; + std::set()))>::type> res; for (const auto& e : *range) res.insert(f(e)); return res; @@ -232,7 +232,7 @@ struct SmartRangeT * @param f Functor that is applied to all elements before computing minimum. */ template - auto min(Functor&& f) -> typename std::remove_reference()))>::type + auto min(Functor&& f) -> typename std::decay()))>::type { using std::min; @@ -241,7 +241,7 @@ struct SmartRangeT auto end = range->end(); assert(it != end); - typename std::remove_reference()))>::type res = f(*it); + typename std::decay()))>::type res = f(*it); ++it; for (; it != end; ++it) @@ -257,7 +257,7 @@ struct SmartRangeT * @param f Functor that is applied to all elements before computing maximum. */ template - auto max(Functor&& f) -> typename std::remove_reference()))>::type + auto max(Functor&& f) -> typename std::decay()))>::type { using std::max; @@ -266,7 +266,7 @@ struct SmartRangeT auto end = range->end(); assert(it != end); - typename std::remove_reference()))>::type res = f(*it); + typename std::decay()))>::type res = f(*it); ++it; for (; it != end; ++it) @@ -283,8 +283,8 @@ struct SmartRangeT * @param f Functor that is applied to all elements before computing maximum. */ template - auto minmax(Functor&& f) -> std::pair()))>::type, - typename std::remove_reference()))>::type> + auto minmax(Functor&& f) -> std::pair()))>::type, + typename std::decay()))>::type> { return std::make_pair(this->min(f), this->max(f)); } From 8fa5f36d1330a0a96a7058410c2348b1cc35372d Mon Sep 17 00:00:00 2001 From: Max Lyon Date: Thu, 28 Nov 2019 11:50:03 +0100 Subject: [PATCH 2/4] make SmartRange sum and avg compatible with Eigen vectors --- src/OpenMesh/Core/Mesh/SmartRange.hh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OpenMesh/Core/Mesh/SmartRange.hh b/src/OpenMesh/Core/Mesh/SmartRange.hh index 5f925e0d..affaeb71 100644 --- a/src/OpenMesh/Core/Mesh/SmartRange.hh +++ b/src/OpenMesh/Core/Mesh/SmartRange.hh @@ -78,13 +78,13 @@ struct SmartRangeT * @param f Functor that is applied to all elements before computing the sum */ template - auto sum(Functor&& f) -> decltype (f(std::declval())+f(std::declval())) + auto sum(Functor&& f) -> decltype (f(std::declval())) { auto range = static_cast(this); auto begin = range->begin(); auto end = range->end(); assert(begin != end); - decltype (f(*begin) + f(*begin)) sum = f(*begin); + decltype (f(*begin)) sum = f(*begin); auto it = begin; ++it; for (; it != end; ++it) @@ -99,13 +99,13 @@ struct SmartRangeT * @param f Functor that is applied to all elements before computing the average. */ template - auto avg(Functor&& f) -> decltype (1.0 * (f(std::declval())+f(std::declval()))) + auto avg(Functor&& f) -> decltype (f(std::declval())) { auto range = static_cast(this); auto begin = range->begin(); auto end = range->end(); assert(begin != end); - decltype (f(*begin) + f(*begin)) sum = f(*begin); + decltype (f(*begin)) sum = f(*begin); auto it = begin; ++it; int n_elements = 1; From 9c806888c06bd84eb7f7eecc355d612eb4f1a3bb Mon Sep 17 00:00:00 2001 From: Max Lyon Date: Thu, 28 Nov 2019 13:42:17 +0100 Subject: [PATCH 3/4] more const related fixes in SmartRange --- src/OpenMesh/Core/Mesh/SmartRange.hh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OpenMesh/Core/Mesh/SmartRange.hh b/src/OpenMesh/Core/Mesh/SmartRange.hh index affaeb71..b87a8bea 100644 --- a/src/OpenMesh/Core/Mesh/SmartRange.hh +++ b/src/OpenMesh/Core/Mesh/SmartRange.hh @@ -78,13 +78,13 @@ struct SmartRangeT * @param f Functor that is applied to all elements before computing the sum */ template - auto sum(Functor&& f) -> decltype (f(std::declval())) + auto sum(Functor&& f) -> typename std::decay()))>::type { auto range = static_cast(this); auto begin = range->begin(); auto end = range->end(); assert(begin != end); - decltype (f(*begin)) sum = f(*begin); + typename std::decay::type sum = f(*begin); auto it = begin; ++it; for (; it != end; ++it) @@ -99,13 +99,13 @@ struct SmartRangeT * @param f Functor that is applied to all elements before computing the average. */ template - auto avg(Functor&& f) -> decltype (f(std::declval())) + auto avg(Functor&& f) -> typename std::decay()))>::type { auto range = static_cast(this); auto begin = range->begin(); auto end = range->end(); assert(begin != end); - decltype (f(*begin)) sum = f(*begin); + typename std::decay::type sum = f(*begin); auto it = begin; ++it; int n_elements = 1; From 0572ae566251646ee9fcd634b1d481dfe1dd8de1 Mon Sep 17 00:00:00 2001 From: Max Lyon Date: Fri, 29 Nov 2019 09:52:53 +0100 Subject: [PATCH 4/4] rename variables to not hide function --- src/OpenMesh/Core/Mesh/SmartRange.hh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/OpenMesh/Core/Mesh/SmartRange.hh b/src/OpenMesh/Core/Mesh/SmartRange.hh index b87a8bea..06e5192b 100644 --- a/src/OpenMesh/Core/Mesh/SmartRange.hh +++ b/src/OpenMesh/Core/Mesh/SmartRange.hh @@ -84,12 +84,12 @@ struct SmartRangeT auto begin = range->begin(); auto end = range->end(); assert(begin != end); - typename std::decay::type sum = f(*begin); + typename std::decay::type result = f(*begin); auto it = begin; ++it; for (; it != end; ++it) - sum += f(*it); - return sum; + result += f(*it); + return result; } /** @brief Computes the average of elements. @@ -105,16 +105,16 @@ struct SmartRangeT auto begin = range->begin(); auto end = range->end(); assert(begin != end); - typename std::decay::type sum = f(*begin); + typename std::decay::type result = f(*begin); auto it = begin; ++it; int n_elements = 1; for (; it != end; ++it) { - sum += f(*it); + result += f(*it); ++n_elements; } - return (1.0 / n_elements) * sum; + return (1.0 / n_elements) * result; } /** @brief Check if any element fulfils condition.