Re: Is there any standard/guarantees for exception safety in STL operations?
Thomas Richter wrote:
nmm1@cam.ac.uk wrote:
As an example of what can be specified, consider a container. It
is possible to specify that insertions, deletions etc. are either
nullified or completed, even when interrupted by exceptions caused
by asynchronous signals. That is tricky to implement efficiently,
so another approach is that any container where an operation is
interrupted in some way must be sanitised by calling a special
method before being used again, and then the same applies. And,
similarly, interrupted sorting never loses or duplicates elements,
or adds junk. All of that is known technology, but is in no sense
a trivial extension.
Let's stick to this example, because it is an excellent one. I don't
think asking for the strong guarantee, i.e. that insertions or
deletions are either done completely or not at all. This is
probably asking for too much. But what I'm asking for is exactly
what you mention below, namely either a method to sanitize the
container, or at least *some* information *how* to sanitize it.
If it was easy to "sanitize", the library would already do that.
The example with a multi-object insert into a vector has the problem
that the already existing objects will have to be moved around to make
room for the new ones. If the object type then have a copy constructor
or a copy assignment that throws, the "move around" can fail.
To restore the original state, you would have to move them back again.
But that can also fail, if the copy constructor or copy assignment
throws another exception. Now what do you do?
Bo Persson
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]