
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Friday 08 August 2008 09:02 am, Mathias Gaunard wrote:
Frank Mori Hess wrote:
boost::shared_ptr<int> s; { int sockfd = socket(PF_INET,SOCK_STREAM,0); if( sockfd!=-1 ) s.reset(&sockfd, boost::lambda::bind(close, * boost::lambda::_1)); }
I've never really used lambda, but it compiles at least. By the way, is there any documentation on the lambda headers (which ones to include to use what)? I didn't see anything in the lambda docs.
Err, nevermind. This will fail when sockfd goes out of scope.
boost::shared_ptr<void> s; { int sockfd = socket(PF_INET, SOCK_STREAM, 0); if( sockfd != -1) s.reset(static_cast<void*>(sockfd), bind(close, static_cast_<int>(_1))); }
make_handle() Emil's handle.hpp creates a shared_ptr which points at a copy of the handle, whose lifetime is also controlled by the shared_ptr. So, you can access the handle through the shared_ptr as well as having the shared_ptr call the handle's cleanup function in its deleter. But my attempt at using lambda stores a pointer to the original handle in the shared_ptr, which becomes invalid as soon as the original handle goes out of scope. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFInElT5vihyNWuA4URAkSFAJ9QwJZhyJ9dtP6yYWPJIsa0bgSKggCfahQG NflCK2b+CjM+x07AqlaifL0= =lvD6 -----END PGP SIGNATURE-----