Boost logo

Boost :

From: Joaquín Mª López Muñoz (joaquin_at_[hidden])
Date: 2007-12-11 12:17:10


David Abrahams ha escrito:

> on Sun Dec 09 2007, Ion Gaztañaga <igaztanaga-AT-gmail.com> wrote:
>
> >
> > 23.1.3.1 Exception safety guarantees [unord.req.except]
> >
> > 1 For unordered associative containers, no clear() function throws an
> > exception. No erase() function throws an exception unless that exception
> > is thrown by the container’s Hash or Pred object (if any).
> >
> > Why this difference? I hope someone knows the answer ;-)
>
> Because unordered associative containers may rehash when erasing.

I think unordered containers are *not* allowed to rehash when erasing:
see N2461, 23.1.3/8

  "...Rehashing invalidates iterators, changes ordering between elements,..."

and 23.1.3/12

  "...The erase members shall invalidate only iterators and references
  to the erased elements."

so the conclusion is that erase can't rehash (incidentally, the implications of
rehashing when erasing a range would be difficult to cope with).

The rationale IMHO behind allowing erase to let Hash or Pred throw is to
allow implementers to write iterators without bucket tracking --the bucket
is computed on the fly when needed, for instance when erasing.

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