From ab1c727936609217d2c6275de8bba0525db474ec Mon Sep 17 00:00:00 2001
From: Philip Trettner <Philip.Trettner@rwth-aachen.de>
Date: Mon, 2 Jul 2018 08:28:04 +0200
Subject: [PATCH] fixed incorrect iterator and some compile errors

---
 Readme.md                        |  3 ++-
 src/polymesh/impl/impl_ranges.hh | 21 ++++++++++++++++++---
 src/polymesh/iterators.hh        |  2 +-
 3 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/Readme.md b/Readme.md
index 4def288..323924a 100644
--- a/Readme.md
+++ b/Readme.md
@@ -22,4 +22,5 @@ Best used with glm and glow.
 * vector, set, map -> range
 * opposite edges (from vertex)
 * cotangens weights etc.
-* smoothing
\ No newline at end of file
+* smoothing
+* make handle.<primitives>() contain only valid ones and provide an all_<primitives>() version
\ No newline at end of file
diff --git a/src/polymesh/impl/impl_ranges.hh b/src/polymesh/impl/impl_ranges.hh
index 50f60c4..45b4383 100644
--- a/src/polymesh/impl/impl_ranges.hh
+++ b/src/polymesh/impl/impl_ranges.hh
@@ -40,7 +40,10 @@ template <class this_t, class ElementT>
 bool smart_range<this_t, ElementT>::any() const
 {
     for (auto h : *static_cast<this_t const *>(this))
+    {
+        (void)h; // unused
         return true;
+    }
     return false;
 }
 
@@ -86,7 +89,10 @@ auto smart_range<this_t, ElementT>::min(FuncT &&f) const -> tmp::decayed_result_
     auto v = f(*it_begin);
     ++it_begin;
     while (it_begin != it_end)
+    {
         v = detail::helper_min(v, f(*it_begin));
+        ++it_begin;
+    }
     return v;
 }
 
@@ -100,7 +106,10 @@ auto smart_range<this_t, ElementT>::max(FuncT &&f) const -> tmp::decayed_result_
     auto v = f(*it_begin);
     ++it_begin;
     while (it_begin != it_end)
+    {
         v = detail::helper_max(v, f(*it_begin));
+        ++it_begin;
+    }
     return v;
 }
 
@@ -114,7 +123,10 @@ auto smart_range<this_t, ElementT>::sum(FuncT &&f) const -> tmp::decayed_result_
     auto s = f(*it_begin);
     ++it_begin;
     while (it_begin != it_end)
+    {
         s = s + f(*it_begin);
+        ++it_begin;
+    }
     return s;
 }
 
@@ -132,6 +144,7 @@ auto smart_range<this_t, ElementT>::avg(FuncT &&f) const -> tmp::decayed_result_
     {
         s = s + f(*it_begin);
         ++cnt;
+        ++it_begin;
     }
     return s / cnt;
 }
@@ -152,6 +165,7 @@ auto smart_range<this_t, ElementT>::weighted_avg(FuncT &&f, WeightT &&w) const -
         auto ee = *it_begin;
         s = s + f(ee);
         ws = ws + w(ee);
+        ++it_begin;
     }
     return s / ws;
 }
@@ -171,6 +185,7 @@ auto smart_range<this_t, ElementT>::aabb(FuncT &&f) const -> polymesh::aabb<type
         auto vv = f(*it_begin);
         r.min = detail::helper_min(r.min, vv);
         r.max = detail::helper_max(r.max, vv);
+        ++it_begin;
     }
     return r;
 }
@@ -239,7 +254,7 @@ int smart_collection<mesh_ptr, tag, iterator>::size() const
 template <class mesh_ptr, class tag, class iterator>
 void smart_collection<mesh_ptr, tag, iterator>::reserve(int capacity) const
 {
-    return primitive<tag>::reserve(*mesh, capacity);
+    return typename primitive<tag>::reserve(*mesh, capacity);
 }
 
 template <class mesh_ptr, class tag, class iterator>
@@ -252,13 +267,13 @@ typename primitive<tag>::template attribute<PropT> smart_collection<mesh_ptr, ta
 template <class mesh_ptr, class tag, class iterator>
 iterator smart_collection<mesh_ptr, tag, iterator>::begin() const
 {
-    return {{this->mesh, primitive<tag>::index(0)}};
+    return {{this->mesh, typename primitive<tag>::index(0)}};
 }
 
 template <class mesh_ptr, class tag, class iterator>
 iterator smart_collection<mesh_ptr, tag, iterator>::end() const
 {
-    return {{this->mesh, primitive<tag>::index(primitive<tag>::all_size(*this->mesh))}};
+    return {{this->mesh, typename primitive<tag>::index(primitive<tag>::all_size(*this->mesh))}};
 }
 
 template <class iterator>
diff --git a/src/polymesh/iterators.hh b/src/polymesh/iterators.hh
index af52cf7..30d1586 100644
--- a/src/polymesh/iterators.hh
+++ b/src/polymesh/iterators.hh
@@ -17,7 +17,7 @@ struct valid_primitive_iterator
     using handle_t = typename primitive<tag>::handle;
 
     valid_primitive_iterator() = default;
-    valid_primitive_iterator(handle_t handle) : handle(handle) { handle.idx = handle.mesh->next_valid_idx_from(handle.idx); }
+    valid_primitive_iterator(handle_t handle) : handle(handle) { this->handle.idx = handle.mesh->next_valid_idx_from(handle.idx); }
 
     handle_t operator*() const { return handle; }
     valid_primitive_iterator& operator++()
-- 
GitLab