Feature proposal: C++11 range-for support
Hi, I have a few utility functions in my code that makes it nicer to iterate over elements of a mesh. I think they might also be useful for other users, so I'd like to present them here for discussion.
They can be used like this:
for(const auto &vh: iter_vertices(mesh)) {...} // vh is a VertexHandle&
If you think this is useful, I would suggest making them member functions of GeometryKernel instead, so they can be used like this:
for(const auto &vh: mesh.iter_vertices()) {...}
Let me know what you think of this, I can prepare a patch if you like.
My current implementation (a bit specific, not templated on mesh type) looks like this:
template<typename I> // iterator type
class RangeIter {
public:
RangeIter(I begin, I end) : begin_(begin), end_(end) {}
I begin() const {return begin_;}
I end() const {return end_;}
private:
I begin_, end_;
};
const inline RangeIter<OpenVolumeMesh::VertexIter>
iter_vertices(const PolyhedralMesh &mesh) {
return {mesh.vertices_begin(), mesh.vertices_end()};
}
const inline RangeIter<OpenVolumeMesh::EdgeIter>
iter_edges(const PolyhedralMesh &mesh) {
return {mesh.edges_begin(), mesh.edges_end()};
}
// ... etc for the other mesh elements
(NB: the code uses C++11 uniform initialization, but I could refactor it to call the constructor explicitly)