3

以下の変換は可能ですか?boost::lambda と単純なバインドを試しましたが、foo を処理して 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
4

1 に答える 1

2

機能合成を行っています。だからあなたはあなたbindのを構成する必要があります。あなたはProcessBar(ConvertFooToBar(...))起こる必要があります。したがって、実際にそれを行う必要があります。

boost::function<void (const Foo&)> f = 
 boost::bind(&ProcessBar, boost::bind(ConvertFooToBar, _1));
于 2012-05-13T00:16:00.860 に答える