Overvoltage redirection

Is the following conversion possible? I tried boost :: lambda and just plain binding, but I try my best to do the in-place conversion without a special helper class that would handle 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
+3
source share
1 answer

You are performing a functional composition. Therefore you must make up your binds. You need to ProcessBar(ConvertFooToBar(...)). Therefore you must do it.

boost::function<void (const Foo&)> f = 
 boost::bind(&ProcessBar, boost::bind(ConvertFooToBar, _1));
+2
source

All Articles