|
Boost : |
From: JOAQUIN LOPEZ MU?Z (joaquin_at_[hidden])
Date: 2007-01-02 13:36:21
----- Mensaje original -----
De: Thorsten Ottosen <thorsten.ottosen_at_[hidden]>
Fecha: Martes, Enero 2, 2007 6:44 pm
Asunto: Re: [boost] Weird behaviour/bug in ptr_map
Para: boost_at_[hidden]
> Thorsten Ottosen wrote:
> > Joshua Moore-Oliva wrote:
[...]
> > It appears that every single erase (including that done by
> >a key) has an assert for the
> >list not being empty!
>
> I could not see that assertion in the 1.34 RC branch? Are your
> examples
> from 1.33?
>
> Here's the definition from 1.34:
>
> 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
> }
>
> This works fine if the map is empty.
Hello Thorsten, this issue was already raised and corrected
on September 2005, you might want to consult the thread at
http://tinyurl.com/tpl54 .
> Wheter the overload that takes an iterator should be allowed to
> accept the end iterator is another issue. I'll give it some
> thought.
My humble opinion is that you shouldn't allow an an end iterator
to be legally passed to erase(iterator), that is, your current
BOOST_ASSERT( before != this->end() );
is conformig. The rational is that erase(end()) is illegal, or
at least undefined behavior, in STL containers.
The additional check
BOOST_ASSERT( !this->empty() );
at the same member function is almost immaterial, since if
the container is empty then end() is the only valid iterator
that can be possibly passed in.
Best,
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk