Boost logo

Boost Users :

From: JOAQUIN LOPEZ MU?Z (joaquin_at_[hidden])
Date: 2005-08-24 12:32:55

----- Mensaje original -----
De: Thorsten Ottosen <nesotto_at_[hidden]>
Fecha: Miércoles, Agosto 24, 2005 6:05 pm
Asunto: Re: [Boost-users] [1.33][ptr_container] bug inerase()

> "JOAQUIN LOPEZ MU?Z" <joaquin_at_[hidden]> wrote in message
> > > size_type erase( const key_type& x ) // nothrow
> > > {
> > > BOOST_ASSERT( !this->empty() );
> Why the BOOST_ASSERT? Do you require that the container
> be non-empty for erase to be callable? Am I missing something?
> >>>>>>
> Hm...I couldn't find anything on this in the standard. Can you
> locate the
> description for map<K,V>::erase( const K&) ?

In 23.1.2 [lib.associative.reqmts], the table has an entry
for the expression "a.erase(k)" saying:

"erases all the elements in the container with key equivalent
to k. returns the number of erased elements."

No precondition is stated that "a" should be nonempty, neither
in the table itself nor in the general requisites for the
table (23.1.2/7), hence "a" is allowed to be empty.

I've taken a closer look at your code and think there are some
more of these overzealous asserts:

* The following in associative_ptr_container.hpp

        iterator erase( iterator first,
                        iterator last ) // nothrow
            BOOST_ASSERT( !this->empty() );

requires again that the container be nonempty. There's no
such precondition in the std for the expression
"a.erase(q1,q2)": the only requisite in 23.1.2/7 is that
[q1, q2) be a valid range, which is compatible with
"a" being empty if q1==q2==a.end() (see 24.1/7, see also
DR151 which addresses an issue with the original erroneous
requirement that q1 be dereferenceable).

* Same problem as above in reversible_ptr_container.hpp.


Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at