Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-10-17 06:26:54


From: "Darin Adler" <darin_at_[hidden]>
> Lets say I have a function object that takes an int parameter. And I have
a
> function that doesn't take any parameters at all. I'd like to be able to
> make the function object be the function, but discard the parameter.
>
> This is sort of the "flip side" of bind.
>
> #include <boost/function.hpp>
>
> void g() { }
>
> int main()
> {
> boost::function<void, int> f;
> f = g;
> f(5);
> }
>
> Is there a nice way of fitting this into Boost.Function, or is it maybe in
> there already? Maybe Boost.Bind offers a way to do this? Or maybe this is
> impossible to implement?

The function object returned by boost::bind will silently discard any extra
parameters:

f = boost::bind(g);

Remember that bind(g, ...) means g(...), even when ... is an empty argument
vector. This is also useful when composing: bind(f, bind(g)) -> f(g()).

This follows from the definition but is probably not easy to spot. :-) I'll
add a note to the documentation.

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