Skip to content

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
    • Help
    • Submit feedback
    • Contribute to GitLab
  • Sign in
OpenVolumeMesh
OpenVolumeMesh
  • Project
    • Project
    • Details
    • Activity
    • Releases
    • Cycle Analytics
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Charts
  • Issues 4
    • Issues 4
    • List
    • Board
    • Labels
    • Milestones
  • Merge Requests 5
    • Merge Requests 5
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Charts
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • OpenVolumeMesh
  • OpenVolumeMeshOpenVolumeMesh
  • Issues
  • #1

Closed
Open
Opened Oct 18, 2016 by Martin Heistermann@mheistermann
  • Report abuse
  • New issue
Report abuse New issue

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)

Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
No due date
0
Labels
None
Assign labels
  • View project labels
Reference: OpenVolumeMesh/OpenVolumeMesh#1