
On Mon, 28 Feb 2011, Tony Cook wrote:
Hi, The following test program highlights an compilation error issue when using a boost::filtered_graph to access graph properties. I am using Boost 1.46.0
#include <boost/graph/adjacency_list.hpp> #include <boost/graph/filtered_graph.hpp>
class TestGraph { class VertexProperties { public: bool mFlag ; } ; class EdgeProperties { public: bool mFlag ; } ; class GraphProperties { public: bool mFlag ; } ;
typedef boost::adjacency_list <boost::vecS, boost::listS, boost::undirectedS, EdgeProperties, VertexProperties, GraphProperties> GraphType ;
template <typename GraphType> class EdgePredicate { public: EdgePredicate () : mpGraph (0) {} public: EdgePredicate (GraphType& vrGraph) : mpGraph (&vrGraph) {} public: template <typename EdgeType> bool operator()(const EdgeType& vEdge) const { return (*mpGraph)[vEdge].mFlag ; } private: GraphType* mpGraph ; } ;
template <typename GraphType> class VertexPredicate { public: VertexPredicate () : mpGraph (0) {} public: VertexPredicate (GraphType& vrGraph) : mpGraph (&vrGraph) {} public: template <typename VertexType> bool operator()(const VertexType& vVertex) const { return (*mpGraph)[vVertex].mFlag ; } private: GraphType* mpGraph ; } ;
typedef boost::filtered_graph<GraphType, EdgePredicate<GraphType>, VertexPredicate<GraphType> > FilteredGraphType ;
...
void foo () { GraphType graph ; FilteredGraphType filter (graph, EdgePredicate<GraphType> (graph), VertexPredicate<GraphType> (graph)) ;
graph [boost::graph_bundle].mFlag = true ; filter [boost::graph_bundle].mFlag ; // ***** Does not compile - see below ... } }
...
gcc 4.5.2 issues the following error message
In member function 'typename boost::graph::detail::bundled_result<Graph, Descriptor>::type& boost::filtered_graph<Graph, EdgePredicate, VertexPredicate>::operator[](Descriptor) [with Descriptor = boost::graph_bundle_t, Graph = boost::adjacency_list<boost::vecS, boost::listS, boost::undirectedS, TestGraph::EdgeProperties, TestGraph::VertexProperties, TestGraph::GraphProperties>, EdgePredicate = TestGraph::EdgePredicate<boost::adjacency_list<boost::vecS, boost::listS, boost::undirectedS, TestGraph::EdgeProperties, TestGraph::VertexProperties, TestGraph::GraphProperties> >, VertexPredicate = TestGraph::VertexPredicate<boost::adjacency_list<boost::vecS, boost::listS, boost::undirectedS, TestGraph::EdgeProperties, TestGraph::VertexProperties, TestGraph::GraphProperties> >, typename boost::graph::detail::bundled_result<Graph, Descriptor>::type = TestGraph::VertexProperties]':
Visual Studio 2005 issues this error at the same line (see above)
error C2440: 'return' : cannot convert from 'TestGraph::GraphProperties' to 'TestGraph::VertexProperties &' test-graph-types.h(78) : see reference to function template instantiation 'TestGraph::VertexProperties &boost::filtered_graph<Graph,EdgePredicate,VertexPredicate>::operator []<boost::graph_bundle_t>(Descriptor)' being compiled with [ Graph=TestGraph::GraphType, EdgePredicate=TestGraph::EdgePredicate<TestGraph::GraphType>, VertexPredicate=TestGraph::VertexPredicate<TestGraph::GraphType>, Descriptor=boost::graph_bundle_t ]
The error originates in boost filtered_graph.hpp line 201
199 // Bundled properties support 200 template<typename Descriptor> 201 typename graph::detail::bundled_result<Graph, Descriptor>::type& 201 operator[](Descriptor x) 203 { return const_cast<Graph&>(this->m_g)[x]; }
The bug appears to be that using Descriptor = boost::graph_bundle somehow selects the wrong return type for operator[](Descriptor) selecting TestGraph::VertexProperties instead of the expected TestGraph::GraphProperties
This is confirmed by redeclaring the GraphType as
typedef boost::adjacency_list <boost::vecS, boost::listS, boost::undirectedS, EdgeProperties, VertexProperties, VertexProperties> GraphType ;
i.e. the type for the graph properties happens to be the same as that used for the Vertex properties.
Now it compiles cleanly!!
Can someone help me locate the origin of this problem. I need to patch this quickly :(
It should be noted that there are no problems accessing vertex and edge bundled properties via a filtered_graph - only the graph bundled properties exhibit this issue.
This is probably a bug -- I'll look at it later this afternoon. -- Jeremiah Willcock