Boost logo

Boost Users :

From: Sigg_at_[hidden]
Date: 2004-07-13 08:39:59


I would like to bind a function which takes a boost::function<void> as
parameter, let's say

void caller(boost::function<void (void)>& f) { f(); }

void foo() {}

boost::function<void (void)> foo_fun = &foo; boost::bind(caller, foo_fun)();

But what if the function has a parameter, for example

void bar(int i) {}

How can I create the folling a function object?

boost::function<void (int)>

The function object should take an int, bind it to bar and then call caller
with the resulting nullary function.

boost::function<void (int)> bar_fun = &bar;

// doesn't work because caller and bar are being composed.
boost:bind(caller, boost::bind(bar_fun, _1))

// doesn't work because caller doesn't accept a unary function.
boost:bind(caller, boost::protect(boost::bind(bar_fun, _1)))

Does anyone have a clean solution for that?

boost::protect doesn't provide the option to evaluate the arguments (_1) but
_not_ perform a composition.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at