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
}
In fact I doubt the correctness of these two lines. First, find() is
defined in ptr_map_adapter class, which is a descendant of
associative_ptr_container. No other find() functions could match the
case here. As for the erase() in line 111, it's actually
std::map::erase(). But this overload should return nothing as specified
in C++ standard (in the case of MS implementation, it returns an
iterator). In no way can it be converted to size_type. Simple
modifications on the code could solve this problem.
Another thing for ptr_map_adapter is one of its Insert() overloads
std::pair
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 }
Another thing for ptr_map_adapter is one of its Insert() overloads
std::pair
insert( key_type& key, value_type x ) I wonder why we don't use const key_type&? Without const modifier,
This is a known bug that is fixed in the cvs. 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
participants (2)
-
Thorsten Ottosen
-
笨 笨