STL转换不适用于BGL

时间:2011-02-09 22:49:38

标签: boost stl graph

我是BGL的新手。我正在尝试将一系列边缘转换为可在我的系统中使用的等效对象。

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));  

但是我收到一个我无法理解的错误:

/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

为什么我会收到此错误?

3 个答案:

答案 0 :(得分:0)

这里all_edges是什么?如果它来自edges(g),则迭代器的值类型为edge_descriptor,而不是my_obj*。您需要应用一个不同的std::transform仿函数,从描述符中获取edge属性,然后将graph::transform应用于它。

答案 1 :(得分:0)

我可能错了,但我怀疑这行

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

旨在表示“接受this指针然后在其上调用graph::transform的一元函数。”如果是这样,不幸的是,这条线并不像你想象的那样。它将当前this指针绑定为graph::transform的参数,然后返回一个仿函数以将graph::transform应用于当前对象。我认为你可能想要的东西更像是

std::mem_fun(&graph::transform)

实际上将graph::transform转换为一元函数,该函数使用其参数作为this指针调用给定的成员函数。你实际上可能想要使用boost::mem_fn,但我不是它如何工作的专家,并且不会试图在这里猜测正确的答案。 : - )

如果我对你要在这里做的事情完全错了,请告诉我,我会删除这个答案。

答案 2 :(得分:0)

仅通过您提供的信息很难说出问题所在。 您尝试绑定的graph::transform函数的签名是什么?