クラスAを考えると、
class A {
public:
A(B&) {}
};
boost::function<boost::shared_ptr<A>(B&)>
オブジェクトが必要です。
アドホック関数を作成したくない
boost::shared_ptr<A> foo(B& b) {
return boost::shared_ptr<A>(new A(b));
}
私の問題を解決するために、lambda::new_ptr をバインドして解決しようとしています。
boost::function<boost::shared_ptr<A> (B&)> myFun
= boost::bind(
boost::type<boost::shared_ptr<A> >(),
boost::lambda::constructor<boost::shared_ptr<A> >(),
boost::bind(
boost::type<A*>(),
boost::lambda::new_ptr<A>(),
_1));
つまり、A の new_ptr と shared_ptr のコンストラクターを 2 つのステップでバインドします。明らかに機能しません:
/usr/include/boost/bind/bind.hpp:236: error: no match for call to ‘(boost::lambda::constructor<boost::shared_ptr<A> >) (A*)’
/usr/include/boost/lambda/construct.hpp:28: note: candidates are: T boost::lambda::constructor<T>::operator()() const [with T = boost::shared_ptr<A>]
/usr/include/boost/lambda/construct.hpp:33: note: T boost::lambda::constructor<T>::operator()(A1&) const [with A1 = A*, T = boost::shared_ptr<A>]
代わりにバインディングを行うにはどうすればよいですか? 前もってありがとう、フランチェスコ