Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redirecting boost bind

Is the following conversion possible? I've tried boost::lambda and just a plain bind, but I'm struggling to make the conversion in-place without a special helper class that would process foo and invoke bar.

struct Foo {}; // untouchable
struct Bar {}; // untouchable

// my code
Bar ConvertFooToBar(const Foo& foo) { ... }

void ProcessBar(const Bar& bar) { ... }

boost::function<void (const Foo&)> f = 
 boost::bind(&ProcessBar, ?);

f(Foo()); // ProcessBar is invoked with a converted Bar
like image 827
The swimming croc Avatar asked May 28 '26 23:05

The swimming croc


1 Answers

You're doing functional composition. So you have to compose your binds. You need ProcessBar(ConvertFooToBar(...)) to happen. So you have to actually do that.

boost::function<void (const Foo&)> f = 
 boost::bind(&ProcessBar, boost::bind(ConvertFooToBar, _1));
like image 58
Nicol Bolas Avatar answered May 31 '26 15:05

Nicol Bolas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!