From: JOAQUIN LOPEZ MU?Z (joaquin_at_[hidden])
Date: 2005-02-11 16:28:28
----- Mensaje original -----
De: Daniel James <daniel_at_[hidden]>
Fecha: Viernes, Febrero 11, 2005 10:45 am
Asunto: [boost] Unordered associative containers and swap's exception
> Hello everyone,
> I've got an exception safety problem implementing the hash
> The draft standard says (from 184.108.40.206):
> 'For unordered associative containers, no swap function throws an
> exception unless that exception is thrown by the copy constructor
> copy assignment operator of the container's Hash or [equality]
> object (if any).'
> This is a problem, because for the container to be valid, its hash
> buckets, equality predicate and hash function need to consistent.
> both the hash and predicate can throw, this is impossible (or
> hard?) to
> achieve. If swapping/copying the first one succeeds, and the
> second one
> throws they won't match. Any ideas on what I should do?
Hi Daniel. I think little can be done here without penalizing
the normal users (i.e. those providing notrow Hash and Pred objects.)
The solution you propose is probably the only way out, but it
incurs an extra indirection each time one of the objects
FWIW, all implementations I've seen simply assume swapping
of these objects won't throw --and this is the case also for
other STL containers, where a simple recovery strategy would be
nonetheless possible. Having a nonthrowing swap, then it is
trivial to have exception-safe strong assignment.
I think this has received attention at comp.std.c++, but
without any definitive conclusion AFAIK.
So my advice is to just assumme Hash and Pred objects won't
throw when being swapped through std::swap and be happy.
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