Boost logo

Boost Users :

From: Thorsten Ottosen (tottosen_at_[hidden])
Date: 2006-03-05 19:05:30


> Hi, all,
>
> I'm a fresh hand to boost. I encounter some problems with ptr_map, in
boost/ptr_container/detail/associative_ptr_container.hpp, line 107 & 111.
>
> size_type erase( const key_type& x ) // nothrow
> {
> BOOST_ASSERT( !this->empty() ); iterator i = find( x );
                  // nothrow // line 107
> if( i == this->end() ) // nothrow
> return 0; // nothrow
> this->remove( i ); // nothrow
> return this->c_private().erase( i.base() ); // nothrow // line 111
> }

This is a known bug that is fixed in the cvs.

> Another thing for ptr_map_adapter is one of its Insert() overloads
>
> std::pair<iterator,bool> insert( key_type& key, value_type x )
>
> I wonder why we don't use const key_type&? Without const modifier,
the compiler would not allow passing constants to it.

That is an exception-safety issue: if const key_type& was
accepted, it could create a leak.

In 1.34 you get a few other choices:

std::auto_ptr<T> p( new T("arg1","arg2") );
map.insert( "key", p );

boost::assign::ptr_map_insert( map )( "key", "arg1", "arg2" );

> At last, never forget to mention my environment: VC 8.0
> No test has been done in other environment.

Please also check that the bug still exists in the cvs:

http://www.boost.org/more/getting_started.html#CVS

Thanks

-Thorsten


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net