|
Boost Users : |
From: Malte Clasen (news_at_[hidden])
Date: 2005-08-23 16:00:21
Hi,
the erase() method (defined in associative_ptr_container.hpp, line 104)
seems a bit strange:
size_type erase( const key_type& x ) // nothrow
{
BOOST_ASSERT( !this->empty() );
iterator i = find( x ); // nothrow
if( i == this->end() ) // nothrow
return 0; // nothrow
this->remove( i ); // nothrow
return this->c_private().erase( i.base() ); // nothrow
}
My compiler (vc++7.1) complained about the unknown find() when I called
erase() on ptr_map. "find" is not declared neither in this class nor in
its base class. The closest valid call I could think of would be
this->c_private().find( x )
. But there seems to be a nicer solution:
size_type erase( const key_type& x ) // nothrow
{
BOOST_ASSERT( !this->empty() );
return this->c_private().erase( x ); // nothrow
}
This compiles fine and does just what I want it to do, even nothrow is
guaranteed (I checked the vc++ reference for std::map). Now I wonder why
erase() is implemented differently in Boost 1.33. Is there anything I
overlooked?
Btw, is there a rationale for the declaration of insert()?
std::pair<iterator,bool> insert( key_type& k, value_type x );
Passing key_type by non-const reference caused some unaesthetic
constructs in my code because return values (temporaries) cannot be used
directly.
Malte
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