Boost logo

Boost :

From: axter (boost_at_[hidden])
Date: 2005-12-27 09:08:20


"Slawomir Lisznianski" <public_at_[hidden]> wrote in message
news:<donook$li2$1_at_[hidden]>...
> Hello,
>
> I've been using ptr_map lately and have a few questions regarding its
> interface.
>
> Below is a signature of `insert' function as declared in
> ptr_map_adapter:
>
> std::pair<iterator,bool> insert( key_type& k, value_type x );
>
> Why is `k' a non-const reference?
>
> To imply ownership transfer, couldn't `x' be of
> `std::auto_ptr<value_type>' type instead?
>
> What happend to std::pair as an argument of insert? Was symmetry with
> std::map dropped for a reason here?
>

>From my test, it doesn't seem as though ptr_map has consistent and reliable
implementation.

I recommend that boost replace the pointer containers with the following
smart pointers:
http://code.axter.com/copy_ptr.h
http://code.axter.com/cow_ptr.h

Example usage:
std::map<int, cow_ptr<foo> > MyPtrMap;

The above type gives you more functionality then the boost::ptr_map type,
and of course, it's interface matches the std::map interface.
Where as the boost::ptr_map type has the following problems:
1. Doesn't allow you to use an abstract pointer
2. Requires a non-constant argument for the insert function
3. Requires value semantics for the operator[] function
4. When assigning value via operator[] from one container to another, you
get object splicing for derived types
5. It doesn't seem to compile on VC++ 6.0, and when it compiles on VC++ 7.1
you get compiler warnings

If you use cow_ptr instead, you don't have the above problems.

There are similar problems in the boost::ptr_set class, which also can be
replaced with cow_ptr or copy_ptr
std::set<cow_ptr<foo> > MyPtrSet;

IMHO, the entire boost pointer container set of classes can be replace with
either cow_ptr and/or copy_ptr, and the result would be a more reliable, and
consistent implementation.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk