[Boost-users] Compilation error using boost::filtered_graph when trying to access graph properties via boost::graph_bundle

42 views
Skip to first unread message

Tony Cook

unread,
Feb 28, 2011, 2:07:29 PM2/28/11
to boost...@lists.boost.org

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.

TIA

Tony

_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Jeremiah Willcock

unread,
Feb 28, 2011, 2:15:29 PM2/28/11
to boost...@lists.boost.org

This is probably a bug -- I'll look at it later this afternoon.

-- Jeremiah Willcock

Jeremiah Willcock

unread,
Feb 28, 2011, 5:43:09 PM2/28/11
to boost...@lists.boost.org
On Mon, 28 Feb 2011, Tony Cook wrote:

Could you please see if this problem still appears in r69404 of the Boost
trunk (just committed)? If you are using a release, you only need to get
boost/graph/properties.hpp and boost/graph/graph_traits.hpp from the trunk
and overwrite your copies. I believe I have fixed the bug -- your example
from above compiles, at least.

-- Jeremiah Willcock

Tony Cook

unread,
Feb 28, 2011, 7:38:01 PM2/28/11
to boost...@lists.boost.org

Hi Jeremiah

** Confirmed fixed :) Thanks **

You might want to look at reverse_graph.hpp as it worked around the problem using:

typename boost::graph_property_type<base_type>::type& operator[](graph_bundle_t)
{ return get_property(*this); }
typename boost::graph_property_type<base_type>::type const& operator[](graph_bundle_t) const
{ return get_property(*this); }

I adapted this fix approach for my local copy of filtered_graph.hpp like so:

typename Graph::graph_bundled& operator[](graph_bundle_t)
{ return const_cast<Graph&>(this->m_g)[boost::graph_bundle]; }
typename Graph::graph_bundled const& operator[](graph_bundle_t) const
{ return this->m_g[boost::graph_bundle]; }

But your fix is general so the code in reverse_graph.hpp is most likely redundant now - I've chucked my local patch away.

Thanks again, Tony

Jeremiah Willcock

unread,
Feb 28, 2011, 10:21:33 PM2/28/11
to boost...@lists.boost.org
On Tue, 1 Mar 2011, Tony Cook wrote:

>
> Hi Jeremiah
>
> ** Confirmed fixed :) Thanks **
>
> You might want to look at reverse_graph.hpp as it worked around the problem using:
>
> typename boost::graph_property_type<base_type>::type& operator[](graph_bundle_t)
> { return get_property(*this); }
> typename boost::graph_property_type<base_type>::type const& operator[](graph_bundle_t) const
> { return get_property(*this); }
>
> I adapted this fix approach for my local copy of filtered_graph.hpp like so:
>
> typename Graph::graph_bundled& operator[](graph_bundle_t)
> { return const_cast<Graph&>(this->m_g)[boost::graph_bundle]; }
> typename Graph::graph_bundled const& operator[](graph_bundle_t) const
> { return this->m_g[boost::graph_bundle]; }
>
> But your fix is general so the code in reverse_graph.hpp is most likely redundant now - I've chucked my local patch away.

Thanks for catching that -- I removed the workaround from
reverse_graph.hpp and it still worked.

Reply all
Reply to author
Forward
0 new messages