From 572c2e93011ee2c78e4471bf7df8c4f8edfbff25 Mon Sep 17 00:00:00 2001 From: Fernando Cacciola Date: Wed, 21 May 2008 17:13:31 +0000 Subject: [PATCH] Fix in halfedge_graph_traits to work-around BGL const-correctness flaw. --- .../graph/halfedge_graph_traits_HalfedgeDS.h | 13 ------------ .../halfedge_graph_traits_Polyhedron_3.h | 20 ++++++++++++++++--- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/halfedge_graph_traits_HalfedgeDS.h b/BGL/include/CGAL/boost/graph/halfedge_graph_traits_HalfedgeDS.h index 4a920c49199..25aa047ecc2 100644 --- a/BGL/include/CGAL/boost/graph/halfedge_graph_traits_HalfedgeDS.h +++ b/BGL/include/CGAL/boost/graph/halfedge_graph_traits_HalfedgeDS.h @@ -70,19 +70,6 @@ public : typedef typename HDS::Vertex::Point Point ; }; -template -struct HDS_halfedge_graph_traits -{ -public : - - typedef HDS_ HDS; - - typedef HDS_all_undirected_edges_const_iterator undirected_edge_iterator; - - typedef typename HDS::Vertex::Point Point ; -}; - - CGAL_END_NAMESPACE #endif // CGAL_BOOST_GRAPH_HALFEDGE_GRAPH_TRAITS_HALFEDGEDS_H diff --git a/BGL/include/CGAL/boost/graph/halfedge_graph_traits_Polyhedron_3.h b/BGL/include/CGAL/boost/graph/halfedge_graph_traits_Polyhedron_3.h index 5a72b78c97f..14f65f4dc36 100644 --- a/BGL/include/CGAL/boost/graph/halfedge_graph_traits_Polyhedron_3.h +++ b/BGL/include/CGAL/boost/graph/halfedge_graph_traits_Polyhedron_3.h @@ -32,6 +32,18 @@ # define CGAL_HDS_PARAM_ class HDS #endif +// +// NOTE: The BGL algorithms are NOT const-correct: i.e., they take a "G const&" +// but instantiate "graph_traits" instead of "graph_traits" +// This is known Boost bug which will eventually be fixed, but in the meantime we need +// to coerce both const and non-const specializations. +// That is, HDS_graph_traits is really the same as HDS_graph_traits +// so graph_traits is also the same as graph_traits. +// Therefore, while, for instance, "graph_traits::vertex_descriptor" +// is conceptually const-correct, it actually corresponds to the non-const handle, +// hence the const_cast<> used below in the functions implementation. +// + CGAL_BEGIN_NAMESPACE // @@ -39,7 +51,7 @@ CGAL_BEGIN_NAMESPACE // template struct halfedge_graph_traits< CGAL::Polyhedron_3 const > - : CGAL::HDS_halfedge_graph_traits< CGAL::Polyhedron_3 const> + : CGAL::HDS_halfedge_graph_traits< CGAL::Polyhedron_3 > // See NOTE above! { }; @@ -50,7 +62,8 @@ inline std::pair const> undirected_edges( Polyhedron_3 const& p ) { typedef typename halfedge_graph_traits< Polyhedron_3 const>::undirected_edge_iterator Iter; - return std::make_pair( Iter(p.edges_begin()), Iter(p.edges_end()) ); + CGAL::Polyhedron_3& ncp = const_cast&>(p); + return std::make_pair( Iter(ncp.edges_begin()), Iter(ncp.edges_end()) ); } template @@ -118,7 +131,8 @@ inline std::pair >::und undirected_edges( Polyhedron_3& p ) { typedef typename halfedge_graph_traits< Polyhedron_3 >::undirected_edge_iterator Iter; - return std::make_pair( Iter(p.edges_begin()), Iter(p.edges_end()) ); + CGAL::Polyhedron_3& ncp = const_cast&>(p); + return std::make_pair( Iter(ncp.edges_begin()), Iter(ncp.edges_end()) ); } template