Roland Schwarz wrote:
I have found that it is bossible to create an in place functor like object by combining function, bind and shared_ptr.
However altough it seems to work I am not sure whether this is safe usage. I would be glad if someone more knowledgeable had a look on it:
class bar { void foo() { } };
boost::function
pfoo; int main(int argc, char* argv[]) { pfoo = boost::bind(&bar::foo, boost::shared_ptr<bar>(new bar)); pfoo(); // ... pfoo = 0; // this operation causes the ~bar dtor to be called return 0; }
Not only is it designed to work.. But it's a documented use case: http://www.boost.org/libs/bind/bind.html#with_member_pointers -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com - 102708583/icq