Boost logo

Boost Users :

Subject: Re: [Boost-users] Function pointer to in/out_degree in BGL
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2010-10-27 04:08:30


On Wed, 27 Oct 2010, langermatze wrote:

>
> I tried this:
>
> typedef boost::adjacency_list<boost::vecS, boost::vecS,
> boost::bidirectionalS> Graph;
> typedef typename boost::graph_traits<Graph>::degree_size_type
> (*FuncPtrType)(typename boost::graph_traits<Graph>::vertex_descriptor, const
> Graph &);
>
> FuncPtrType funcPtr = boost::in_degree<Graph>;
>
> The error I'm getting:
> error: no matches converting function ‘in_degree’ to type ‘size_t (*)(long
> unsigned int, const class boost::adjacency_list<boost::vecS, boost::vecS,
> boost::bidirectionalS, boost::no_property, boost::no_property,
> boost::no_property, boost::listS>&)’
> /usr/include/boost/graph/detail/adjacency_list.hpp:1058: error: candidates
> are: template<class Config> typename Config::degree_size_type
> boost::in_degree(typename Config::vertex_descriptor, const
> boost::undirected_graph_helper<C>&)
> /usr/include/boost/graph/detail/adjacency_list.hpp:1649: error:
> template<class Config> typename Config::degree_size_type
> boost::in_degree(typename Config::vertex_descriptor, const
> boost::directed_edges_helper<Config>&)
>
> Sounds reasonable since the signature of in_degree is way more complex than
> my function pointer signature. I couldn't find a way to get the correct
> Config template for my Graph class, that's why I tried to pass the Graph
> class itself but apparently that's not how it works.
>
> I also tried casting which ends up in the "improper use of overloaded
> function" error that you mentioned:
>
> FuncPtrType funcPtr = static_cast<FuncPtrType>(boost::in_degree<Graph>);
>
> error: invalid static_cast from type ‘<unresolved overloaded function type>’
> to type ‘size_t (*)(long unsigned int, const
> boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS,
> boost::no_property, boost::no_property, boost::no_property, boost::listS>&)’
>
> As for your concerns about efficiency, I'd ultimately use the function
> pointer as an additional template for the visitor which then shouldn't
> affect code efficiency at all but avoid code duplication only.

If you're doing that, you might as well make your own function objects
(that are not function pointers) that call in_degree and/or out_degree
directly in their operator()() implementations. That will be faster and
avoid the casting problems you are having.

-- Jeremiah Willcock


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net