
On Feb 20, 2009, at 10:53 PM, Yang Zhang wrote:
Howard Hinnant wrote:
On Feb 20, 2009, at 1:27 PM, Yang Zhang wrote:
From http://www.boost.org/doc/libs/1_36_0/libs/smart_ptr/scoped_ptr.htm :
"If scoped_ptr had a release() member, it would become possible to transfer ownership of the held pointer, weakening its role as a way of limiting resource lifetime to a given context. Use std::auto_ptr where transfer of ownership is required. (supplied by Dave Abrahams)"
But there already is a way to escape the scope, via swap().
Would it make more sense to just provide release() and have users specify const if they want? (const scoped_ptr/scoped_array would effectively disallow swapping/releasing.) <opinion> http://home.roadrunner.com/~hinnant/unique_ptr03.html (search for "scoped_ptr") </opinion>
Nice. Thanks for the pointer (pun intended). I take it boost does not have unique_ptr, correct? I checked in Boost.TR1 and found nothing. I did find boost::interprocess::unique_pointer, but that appears to be different.
You might keep a close eye on boost::interprocess::unique_pointer. Ion knows what he's doing and is in sync with me. His version is probably changing to take advantage of a newly developed generic move emulation library that he's been working on, but I am not sure. I'm sure Ion will chime in. Whatever he says goes. I have 100% confidence in him in this matter. :-)
I did some digging, and I did find mention of this file on the gcc mailing lists - I take it this implementation is being included in GNU libstdc++?
I don't know.
Lastly, I didn't see any rvalue references in this file. I was under the impression that the implementation of unique_ptr leverages rvalue references. Is this why there are const_casts present in the code?
The referenced file is a pure C++03 emulation and doesn't contain C+ +0X code (e.g. rvalue references). The emulation is not perfect and so yes, const_cast is used to in some places to emulate (as much as possible) C++0X language features. A combined C++03/C++0X implementation is more likely to be found in a boost implementation such as boost::interprocess::unique_pointer (but I am not sure). -Howard