![]() |
Boost : |
Subject: Re: [boost] [parameter] Boost.Graph program not responding at run-time
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2011-12-03 15:11:44
On Sat, Dec 3, 2011 at 2:28 PM, Jeremiah Willcock <jewillco_at_[hidden]> wrote:
> On Sat, 3 Dec 2011, Lorenzo Caminiti wrote:
>> If I move the call to boost::depth_first_search into a template
>> depth_first_search_impl and out of the Boost.Parameter function body,
>> the code compiles (both MSVC and GCC with latest Boost from trunk) but
>> the executable runs forever and prints nothing to cout... What am I
>> doing wrong?
>
> I tried your code with GCC 4.6.0 and it worked just fine as you pasted it
> below. I get:
>
> order of discovery: u v y x w z
> order of finish: x y v u z w
>
> as the result. You are returning an invalid pointer from
> default_color_map(), though; &colors[0] becomes invalid when colors is
> destroyed at the end of the function.
Oops... thanks, that was actually the issue, after I fixed the invalid
pointer the code runs fine.
BTW, what's the best way to generate a default_color_map for
Boost.Graph like the one below?
template< typename Size, typename IndexMap >
boost::iterator_property_map<boost::default_color_type*, IndexMap,
boost::default_color_type, boost::default_color_type&>
default_color_map ( Size const& num_vertices, IndexMap const& index_map )
{
std::vector<boost::default_color_type> colors(num_vertices);
return &colors[0]; // *** Error: invalid ptr... ***
}
BOOST_PARAMETER_NAME(graph)
BOOST_PARAMETER_NAME(visitor)
BOOST_PARAMETER_NAME(root_vertex)
BOOST_PARAMETER_NAME(index_map)
BOOST_PARAMETER_NAME(color_map)
BOOST_PARAMETER_FUNCTION(
(void),
depth_first_search,
tag,
(required
(graph, *(is_incidence_and_vertex_list_graph<boost::mpl::_>))
)
(optional
(visitor, *, boost::dfs_visitor<>())
(root_vertex,
(vertex_descriptor<tag::graph::_>),
*boost::vertices(graph).first)
(index_map,
*(is_integral_property_map_of_key< boost::mpl::_,
vertex_descriptor<tag::graph::_> >),
boost::get(boost::vertex_index, graph))
(in_out(color_map),
*(is_property_map_of_key< boost::mpl::_,
vertex_descriptor<tag::graph::_> >),
default_color_map(boost::num_vertices(graph),
index_map)) // *** Note: color map used here ***
)
) {
return depth_first_search_impl<graph_type, visitor_type, root_vertex_type,
index_map_type, color_map_type>(graph, visitor, root_vertex,
index_map, color_map);
}
--Lorenzo
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk