考虑一个 CGAL::Arrangement_2
。现在,我必须像这样遍历它:
using MyArrangement = CGAL::Arrangement_2<MyTraits, MyDcel>;
for(MyArrangement::Face_handle face = map.faces_begin(); face != map.faces_end(); ++face)
{
do_stuff(face);
}
如果我尝试将其迁移到使用 C++11 样式的基于范围的 for
循环,如下所示:
for(auto face : gMap)
{
do_stuff(face)
}
我收到以下错误(强调我的错误):
Error:(1385, 13) invalid range expression of type 'CGAL::Arrangement_2 > >, true>, std::__1::vector > >, true> >, std::__1::allocator > >, true> > > >, CGAL::Arr_consolidated_curve_data_traits_2 > >, true> >, int> >, CGAL::Arr_extended_dcel > >, true>, std::__1::vector > >, true> >, std::__1::allocator > >, true> > > >, CGAL::Arr_consolidated_curve_data_traits_2 > >, true> >, int> >, GIS_vertex_data, GIS_halfedge_data, GIS_face_data, CGAL::Arr_vertex_base > >, true> > >, CGAL::Gps_halfedge_base > >, true> >, CGAL::_Unique_list > >, CGAL::Gps_face_base> >'; no viable 'begin' function available
如果我将 for 循环更改为使用 auto &face
或 const auto &face
,错误是相同的。
有没有人对此有解决方法,或者一些好的包装器可以让它工作?我试图避免不得不诉诸于使用带有 lambda 参数的这种怪异行为:
template<typename F>
void for_each_face(MyArrangement &map, F callback)
{
for(MyArrangement::Face_handle f = map.faces_begin(); f != map.faces_end(); ++f)
{
callback(f);
}
}
最佳答案
迭代人脸的范围基础版本是face_handles()
.您对顶点 (vertex_handles()
) 和半边 (halfedge_handles()
) 有类似的函数。
关于c++ - 对 CGAL 类型使用基于范围的 for 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54403533/