开发者

STL transform is not working with BGL

开发者 https://www.devze.com 2023-02-10 02:56 出处:网络
I\'m new to BGL. I\'m trying to transform a range of edges to equivalent objects usable in my system.

I'm new to BGL. I'm trying to transform a range of edges to equivalent objects usable in my system.

std::vector<my_obj*> return_value(distance(all_edges.first, all_edges.second));
std::transform(all_edges.first, all_edges.second, return_value.begin(),
               bind(&graph::transform, this, _1));  

But I'm getting an error which I couldn't understand:

/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/stl_algo.h: In function `_OutputIterator std::transform(_InputIterator, _InputIterator, _OutputIterator, _UnaryOperation) [with _InputIterator =boost::detail::adj_list_edge_iterator<std::_List_iterator<void*>, boo        st::detail::out_edge_iter<std::_List_iterator<boost::detail::sep_<void*, boost::property<boost::        edge_bundle_t, my_obj*, boost::no_property> > >, void*, boost::detail::edge_desc_impl<boost::dir        ected_tag, void*>, ptrdiff_t>, boost::adjacency_list<boost::listS, boost::listS, boost::directed        S, my_obj*, my_obj*, boost::no_property, boost::listS> >, _OutputIterator = __gnu_cxx::__normal_        iterator<my_obj**, std::vector<my_obj*, std::allocator<my_obj*> > >, _UnaryOperation = boost::la        mbda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<3, boost::lambda::        function_action<3, boost::lambda::detail::unspecified> >,
      2    boost::tuples::tuple<my_obj*(Graph::*const)(boost::detail::edge_desc_impl<boost::directed_tag        , void*>), Graph* const, const boost::lambda::lambda_functor<boost::lambda::placeholder<1> >,boo        st::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_t        ype,boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > >]':
      3 Isrc/icn_graph.cxx:70:   instantiated from here
      4 /usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/stl_algo.h:789: error:         no match for call to `(boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::        lambda::action<3, boost::lambda::function_action<3, boost::lambda::detail::unspecified> >, boost        ::tuples::tuple<my_obj*(Graph::*const)(boost::detail::edge_desc_impl<boost::directed_tag, void*>        ), Graph* const, const boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, boost::tup        les::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, bo        ost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > >) (boost::detail:        :edge_desc_impl<boost::directed_tag, void*>)'
      5 /usr/include/boost/lambda/detail/lambda_functors.hpp:137: note: candidates are: typename T::sig<  开发者_开发百科      boost::tuples::null_type>::type boost::lambda::lambda_functor<Base>::operator()() const [with T        = boost::lambda::lambda_functor_base<boost::lambda::action<3, boost::lambda::function_action<3,        boost::lambda::detail::unspecified> >, boost::tuples::tuple<my_obj*(Graph::*const)(boost::detail        ::edge_desc_impl<boost::directed_tag, void*>), Graph* const, const boost::lambda::lambda_functor        <boost::lambda::placeholder<1> >, boost::tuples::null_type, boost::tuples::null_type, boost::tup        les::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, bo        ost::tuples::null_type> >]
      6 /usr/include/boost/lambda/detail/lambda_functors.hpp:145: note:                 typename T::sig<        boost::tuples::tuple<A&, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null        _type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tupl        es::null_type, boost::tuples::null_type, boost::tuples::null_type> >::type boost::lambda::lambda        _functor<Base>::operator()(A&) const [with A = boost::detail::edge_desc_impl<boost::directed_tag        , void*>, T = boost::lambda::lambda_functor_base<boost::lambda::action<3, boost::lambda::functio        n_action<3, boost::lambda::detail::unspecified>>, boost::tuples::tuple<my_obj*(Graph::*const)(bo        ost::detail::edge_desc_impl<boost::directed_tag, void*>), Graph* const, const boost::lambda::lam        bda_functor<boost::lambda::placeholder<1> >,boost::tuples::null_type, boost::tuples::null_type,        boost::tuples::null_type, boost::tuples::null_type,boost::tuples::null_type, boost::tuples::null        _type, boost::tuples::null_type> >]
      7

Why do I get this error?


What is all_edges here? If it is from edges(g), the value type of the iterator is edge_descriptor, not my_obj*. You will need to apply a different std::transform functor that gets your edge property from the descriptor then applies graph::transform to it.


I could be wrong about this, but I suspect that the line

bind(&graph::transform, this, _1)

is intended to mean "a unary function that takes in a this pointer and then invokes graph::transform on it." If so, unfortunately this line doesn't do what you think it does. It instead binds the current this pointer as the argument to graph::transform, then returns a functor to apply graph::transform to the current object. I think what you probably want is something more along the lines of

std::mem_fun(&graph::transform)

Which does actually turn graph::transform into a unary function that invokes the given member function using its argument as the this pointer. You actually probably want to use boost::mem_fn for this, but I'm not an expert on how it works and won't try to guess the correct answer here. :-)

If I'm totally wrong about what you're trying to do here, let me know and I'll remove this answer.


It's hard to tell what the problem is with only the information you provided. What is the signature of the graph::transform function you're trying to bind?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号