Boost logo

Boost Users :

From: Thorsten Ottosen (tottosen_at_[hidden])
Date: 2006-02-17 06:54:07


Bill Buklis wrote:
> The following code does not successfully compile:
>
> boost::ptr_map<int,int> testmap;
>
> testmap.erase(5);
>
>
> The compiler (MSVC 7.1) complains that the identifier "find" is unknown
> inside the erase function (see below). The class does have a find function
> as "testmap.find(5)" compiles as expected. I expect it's a mismatch with the
> embedded classes.
>
> Taken directly from associate_ptr_container.hpp:
>
> size_type erase( const key_type& x ) // nothrow
> {
> BOOST_ASSERT( !this->empty() );
> iterator i = find( x ); // ERROR ON THIS LINE
> if( i == this->end() )
> return 0;
> this->remove( i );
> return this->c_private().erase( i.base() );
> }
>
>
> The following workaround does work at least, but the above should also,
> shouldn't it?

It should work :-) This was a bug in the version that you're using. The
new implementation is

       size_type erase( const key_type& x ) // nothrow
         {
             iterator i( this->c_private().find( x ) ); // nothrow
             if( i == this->end() ) // nothrow
                 return 0u; // nothrow
             this->remove( i ); // nothrow
             return this->c_private().erase( x ); // nothrow
         }

-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