Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-12-27 11:43:26


From: "Karl Nelson" <kenelson_at_[hidden]>
> > From: "Karl Nelson" <kenelson_at_[hidden]>
> > > with functor, but once function and bind (horrible, horrible name!!)
> >
> > You seem to use "bind" yourself. ;-)
>
> Yes. I used it for the same function as STL does.
>
> Ie.
>
> STL:
> bind1st(less<int>(),2)

boost::bind(less<int>(), 2, _1)

> SigC:
>
> void foo(int);
> Slot0<void> sl=bind(&foo,1);

boost::bind(foo, 1)

> boost::bind:
>
> bind(&X::f0,&x)();

STL: bind1st(mem_fun(&X::f1), &x)

> bind in the boost sense is using the term bind to mean something
> other than arguments. It is meaning combine an object and method
> to a functor. True the object is a hidden object to a method, but
> this still seems odd.

No, bind always binds arguments. The bind(&X::f, &x) notation is a syntactic
sugar for bind(mem_fn(&X::f), &x), nothing else; bind itself does not
distinguish between objects and "ordinary" arguments. You can bind the
argument of the member function as well:

boost::bind(&X::f1, _1 /* object left unbound */, 5);

Of course if you buy the semantic analogy between X::f() and f(X &) this
syntax feels more natural. Even if you don't, the syntactic convenience is -
IMHO - worth it.

--
Peter Dimov
Multi Media Ltd.

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