Search code examples
cgal

CGAL handle to iterator comparison


I've read up on forums that CGAL iterator/circulator are type-castable to corresponding handles implicitly. I should be able to use iterators/circulators "as if they were handles". Why then I get an error if I try to compare them? Here is an example:

typedef CGAL::Constrained_Delaunay_triangulation_2<K, Tds> CDT;
typedef CDT::Vertex_handle Vertex_handle;
typedef CDT::Vertex_iterator Vertex_iterator;
...
CDT cdt;
Vertex_handle va = cdt.insert(Point(0,0));
for(Vertex_iterator i=cdt.vertices_begin();...) {
  va=i;  /* Compiles Ok */
  if(va==i) { ... } /* Pages of Error messages */
}

This example is adapted from CGAL Delaunay meshing demo


Solution

  • The solution was simple...

    for(Vertex_iterator i=cdt.vertices_begin();...) 
    {
      va=i; /* Implicit dereferencing */
      /* Implicit deref. doesn't work, so use explicit dereferencing */       
      if(va==Vertex_handle(i)) { ... }
    }