Boost logo

Boost :

From: Jeremy Siek (jsiek_at_[hidden])
Date: 2001-12-12 11:59:29


On Wed, 12 Dec 2001, Peter Dimov wrote:
>
> 1. There are no 0, 1, 2 versions of bind. Function objects returned by bind
> don't know in advance their argument types (or even arity.)
>
> 2. bind can compose. See libs/bind/bind_as_compose.cpp.

Ahh, thanks! And it is well documented too :)

Now on to another problem.

Some BGL iterators dereference return by value. The bind generated
function objects take their parameters by reference. This causes the
following to fail:

#include <iostream>
#include <algorithm>
#include <boost/graph/adjacency_list.hpp>
#include <boost/bind.hpp>

typedef boost::adjacency_list<boost::vecS, boost::listS> Graph;
typedef boost::graph_traits<Graph>::vertex_descriptor vertex_t;

void print_vertex(vertex_t x) { std::cout << x << ' '; }

int main()
{
  Graph G(5);
  vertex_t v = *vertices(G).first;
  std::for_each(adjacent_vertices(v, G).first,
                adjacent_vertices(v, G).second,
                boost::bind(&print_vertex, _1));
  return 0;
}

Here's the g++ error:

bind_input_iter.cpp:16: instantiated from here
/usr/include/gcc/darwin/2.95.2/g++/stl_algo.h:83: initialization of
non-const reference type `void *&'
/usr/include/gcc/darwin/2.95.2/g++/stl_algo.h:83: from rvalue of type
`void *'
/Users/jsiek/boost/boost/bind/bind_template.hpp:31: in passing argument 1
of `boost::_bi::bind_t<void,void (*)(void
*),boost::_bi::list1<boost::_bi::arg<1> > >::operator ()<void *>(void *&)'

I don't see an easy way to fix the problem :(

Cheers,
Jeremy

----------------------------------------------------------------------
 Jeremy Siek http://www.osl.iu.edu/~jsiek/
 Ph.D. Student, Indiana Univ. B'ton email: jsiek_at_[hidden]
 C++ Booster (http://www.boost.org) office phone: (812) 855-3608
----------------------------------------------------------------------


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk