Proposal to add smart_ptr to the boost library

Since the current smart_ptr (policy_ptr) class at boost vault is on hold, I like to propose adding the following smart_ptr class to the boost library: http://code.axter.com/smart_ptr.h IMHO, the above class has more functional features, than the class in the boost vault, and the class is ready for use. The smart pointer is very exchangeable with each other, and it has easy to use policy options. It has an optional lock policy that can be used on all three main ownership policy types (deep_copy, COW, & Shared). It has three methods of cloning policies that can give different levels of generic coding and/or slicing avoidance. The shared and COW policy, can use reference-count, reference-link, and reference-intrusive polices. In my performance test, the shared and COW policies along with reference-link policy, are able to out perform the boost::shared_ptr. It can be used with non-compliant compilers like VC++6.0 and Borland BCC55. And on more compliant compilers (VC++7.x, 8.0, GNU 3.x, 4.x), it has additional capabilities, which allows it to be exchangeable with different policy types, and derive types (T). Like boost::week_ptr, the smart_ptr supports value (pointee) comparison semantics, so it can be used in an associated container like std::map and std:set. Unlike the boost pointer containers, this smart pointer can be used as the first type in the std::map container. The smart_ptr can be used as a shared-pointer, clone smart pointer, Copy-On-Write pointer, and a synchronized smart pointer. Since there's already a similar class in the boost vault, that indicates that there's already interest in this type of class. So IMHO, the question really should be, should we continue to wait for a class in the vault that might never get completed, and might not have all the functionality available in the above smart_ptr? Or should this class be pushed through in parallel to the current vault policy_ptr class. To see a validation test, and performance test, use the following code: http://code.axter.com/boost_ptr_containers/main.cpp http://code.axter.com/smart_ptr.h http://code.axter.com/shape_test.h http://code.axter.com/copy_ptr.h http://code.axter.com/cow_ptr.h

On 1/24/06, David Maisonave <dmaisonave@commvault.com> wrote:
Since the current smart_ptr (policy_ptr) class at boost vault is on hold, I like to propose adding the following smart_ptr class to the boost library: http://code.axter.com/smart_ptr.h
You can propose your class(es) for review, but you will need to provide documentation and unit-tests if you expect your code to stand a snowball's chance of being accepted into Boost. See http://boost.org/more/submission_process.htm for some more info. -- Caleb Epstein caleb dot epstein at gmail dot com

On 01/24/2006 09:45 AM, David Maisonave wrote:
Since the current smart_ptr (policy_ptr) class at boost vault is on hold, I like to propose adding the following smart_ptr class to the boost library:
Could you eliminate the tabs and reformat to something like 75 or 80 columns to ease reading. An example is in http://boost-consulting.com/vault/Memory. Also, boost convention is .hpp (or hxx or something like that) extension instead of .h.
IMHO, the above class has more functional features, than the class in
I notice policy_ptr has a weak_ptr class. Does axter smart_ptr has something similar to handle cycles in pointer graph?
the boost vault, and the class is ready for use.
I've compiled and run the policy_ptr tests with g++. [snip]
In my performance test, the shared and COW policies along with reference-link policy, are able to out perform the boost::shared_ptr.
Could this be due to shared_ptr having two refcounts and smart_ptr having just one? [snip] Of course you mean weak_ptr? Does this support mean cycles can occur if they're broken by the smart_ptr's version (if any) of boost::weak_ptr?

On 01/26/2006 06:38 AM, Larry Evans wrote: [snip]
[snip]
Of course you mean weak_ptr? Does this support mean cycles can occur
OOPS. The above line should have been preceded by:
Like boost::week_ptr, the smart_ptr supports value (pointee) comparison semantics, so it can be used in an associated container like std::map

On 01/26/2006 06:38 AM, Larry Evans wrote: [snip]
Could you eliminate the tabs and reformat to something like 75 or 80 columns to ease reading. An example is in http://boost-consulting.com/vault/Memory. I just removed this since I think everybody's had a chance to download it. If not, please let me know. [snip]

David Maisonave wrote:
Since the current smart_ptr (policy_ptr) class at boost vault is on hold, I like to propose adding the following smart_ptr class to the boost library:
smart_ptr& operator=(const smart_ptr& Src) { if (m_type != m_type) { Src.lock(); m_ownership_policy.assign(m_type, m_clone_fct, Src.m_type, Src.m_clone_fct, Src.m_ownership_policy, m_ownership_policy); Src.unlock(); } return *this; } You need a unit test. ;-)
participants (4)
-
Caleb Epstein
-
David Maisonave
-
Larry Evans
-
Peter Dimov