std::bind を使用してメンバー関数を boost::signals2::signal::connect() に渡すのは安全ですか? つまり、boost::bind と std::bind は交換可能ですか?
VC++ 2010 SP1 でコンパイルできますが、テンプレート コードは私の頭をはるかに超えており、未定義の動作領域に足を踏み入れているのではないかと心配しています。
std::bind を使用してメンバー関数を boost::signals2::signal::connect() に渡すのは安全ですか? つまり、boost::bind と std::bind は交換可能ですか?
VC++ 2010 SP1 でコンパイルできますが、テンプレート コードは私の頭をはるかに超えており、未定義の動作領域に足を踏み入れているのではないかと心配しています。
I'm not experienced in the subject by I would expect connect
to take anything that implements a valid function call operator. It should be safe to call it with any function or function object that matches the signature, be it boost::bind, std::bind or anything else. Boost libraries are designed to be generic, so they usually don't go picking each others implementation details.
このconnect
関数はboost::function
オブジェクトを受け取ります。これは、基本的に、定義されているすべてのものを包む汎用ラッパーです。operator()
したがって、拘束しているものとまったく同じくらい安全です。
たとえば、これはかなり安全です。
boost::shared_ptr<ClassName> pValue = boost::make_shared<ClassName>(...);
signal.connect(boost::bind(&ClassName::FuncName, pValue, ...);
boost::shared_ptr
データの一部として を格納するため、これはかなり安全です。
ClassName *pValue = new ClassName(...);
signal.connect(boost::bind(&ClassName::FuncName, pValue, ...);
これは条件付きで安全です。その接続がまだ存在しているときに を実行すると、即座に安全ではなくなりますdelete pValue
。
個人的には、「条件付きで安全」をあまり信じていませんが、それはあなた次第です。ポイントは、バインド先のすべてが、バインドされてboost::bind
いる限り存在し続けなければならないということです。