[BGL] boost::bind fails to compile when used with edge iterators in for_each

Hi I'm trying to run a functor over edges from a graph using for_each however it fails when the iterators are edges. The same technique works for iterators to vertices. Here is the compiler error: g++ -o bind_edge_test bind_edge_test.cpp /usr/lib/gcc/i686-pc-linux-gnu/4.1.1/include/g++-v4/bits/stl_algo.h: In function '_Function std::for_each(_InputIterator, _InputIterator, _Function) [with _InputIterator = boost::detail::undirected_edge_iter<std::_List_iterator<boost::list_edge<void*, boost::property<boost::edge_name_t, unsigned int, boost::no_property>
, boost::detail::edge_desc_impl<boost::undirected_tag, void*>, int>, _Function = boost::_bi::bind_t<void, Op, boost::_bi::list2<boost::arg<1>, boost::_bi::value<int> > >]': bind_edge_test.cpp:79: instantiated from here /usr/lib/gcc/i686-pc-linux-gnu/4.1.1/include/g++-v4/bits/stl_algo.h:159: error: no match for call to '(boost::_bi::bind_t<void, Op, boost::_bi::list2<boost::arg<1>, boost::_bi::value<int> > >) (boost::detail::edge_desc_impl<boost::undirected_tag, void*>)'
I've attached the file. Thanks for the help. -- sashan http://sashang.orcon.net.nz/

On Jun 1, 2007, at 3:04 AM, Sashan Govender wrote:
Hi
I'm trying to run a functor over edges from a graph using for_each however it fails when the iterators are edges. The same technique works for iterators to vertices. Here is the compiler error:
g++ -o bind_edge_test bind_edge_test.cpp /usr/lib/gcc/i686-pc-linux-gnu/4.1.1/include/g++-v4/bits/stl_algo.h: In function '_Function std::for_each(_InputIterator, _InputIterator, _Function) [with _InputIterator = boost::detail::undirected_edge_iter<std::_List_iterator<boost::list_ed ge<void*, boost::property<boost::edge_name_t, unsigned int, boost::no_property>
, boost::detail::edge_desc_impl<boost::undirected_tag, void*>, int>, _Function = boost::_bi::bind_t<void, Op, boost::_bi::list2<boost::arg<1>, boost::_bi::value<int> > >]': bind_edge_test.cpp:79: instantiated from here /usr/lib/gcc/i686-pc-linux-gnu/4.1.1/include/g++-v4/bits/stl_algo.h: 159: error: no match for call to '(boost::_bi::bind_t<void, Op, boost::_bi::list2<boost::arg<1>, boost::_bi::value<int> > >) (boost::detail::edge_desc_impl<boost::undirected_tag, void*>)'
Unfortunately, this isn't an easy problem to solve. The edge iterators in the BGL return temporary edge objects when you dereference them. Bind, however, cannot accept temporary objects... this is the dreaded "forwarding problem". It's the same reason you can't pass literals to a bound function object, e.g., bind(std::plus<int>, _1, _2)(17, 42); // error: no match for call to... Unfortunately, this probably means that for_each with bind and edge iterators just won't work. There is some hope: the next version of the C++ standard will eventually fix this problem. - Doug

Sashan Govender wrote:
Hi
I'm trying to run a functor over edges from a graph using for_each however it fails when the iterators are edges. The same technique works for iterators to vertices. Here is the compiler error:
[...]
I've attached the file. Thanks for the help.
Your program compiles with the latest version of Bind. It should work with 1.34, too, although I haven't checked. Are you using 1.33?
participants (3)
-
Doug Gregor
-
Peter Dimov
-
Sashan Govender