Is it possible to use std :: bind with boost :: signals2?

Is it possible to use std :: bind to pass a member function for boost :: signals2 :: signal :: connect ()? In other words, boost :: bind and std :: bind are interchangeable?

It compiles with VC ++ 2010 SP1, but the template code goes through my head, and I'm afraid that I might risk an undefined behavior territory.

+5
source share
2 answers

A function connecttakes an object boost::function, which is basically a common wrapper for everything that has a operator()specific to it. Therefore, it is just as safe as what you bind.

For example, it is safe enough:

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, , .

+1

, , connect , . , , boost:: bind, std:: bind - . Boost , .

+2

All Articles