Re: Erase in a map

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Norbert Unterberg wrote:
Ulrich Eckhardt schrieb:

The typically used solution is this:

while(it!=end)
if(predicate(*it))
container.erase(it++);

erase() returns an iterator of the element after the erased ones.

According to my pre-release copy of the standard, that is a requirement for
containers that model the sequence requirement. However, that same copy
mandates a void returntype for erase(iterator) of [multi](set|map), and
that is effectively what is done by several implementations of the
standardlibrary. I believe that the Dinkumware library returns iterators as
an extension or for backward compatibility with the STL.

Uli

.



Relevant Pages

  • Re: comparison of objects
    ... the standard function is being used versus your redefinition. ... User's interface would give means to iteration, ... ** User and implementor interface: ... An iterable is an object for which an iterator can be defined. ...
    (comp.lang.lisp)
  • Re: Using std::equal with an empty set.
    ... I think that the Standard must states explicitly that in case of an empty ... Vladimir Grigoriev ... so you have found an iterator for which the condition isn't true? ...
    (microsoft.public.vc.language)
  • Re: Erase in a map
    ... According to the standard, map::erase does return nothing, whereas, say, ... returning an iterator as a conforming extension, ... vector::erase on the other hand invalidates ... erase() method does return an iterator). ...
    (microsoft.public.vc.stl)
  • Re: Using std::equal with an empty set.
    ... I believe that when the interval is empty then *otherwise* is true!:) ... Vladimir Grigoriev wrote: ... However if to follow the Standard description it seems that in this case ... It must hold for every iterator in the range [first, ...
    (microsoft.public.vc.language)
  • Re: Erase in a map
    ... containers that model the sequence requirement. ... do what sequence containers do, returning the next iterator for erase, so it's becoming increasingly safe to rely on this. ...
    (microsoft.public.vc.stl)