Re: Swap function of STL container
"Victor Bazarov" <v.Abazarov@comAcast.net> wrote in message
news:fsip6q$6g5$1@news.datemas.de
George wrote:
All swap functions in STL container class is exception safe and
nothrow, right?
No.
I have searched for swap for vector and deque, but
seems no explicit document about the exception safe level.
What about "[lib.container.requirements]/10" where it says,
<< - no swap() function throws an exception unless that exception
is thrown by the copy constructor or assignment operator of
the container's Compare object (if any; see 23.1.2).>>
?
Note that vector and deque are among containers that don't in fact have
Compare object, so for them, swap() is indeed guaranteed not to throw.
Even for associative containers, you need to provide a rather exotic
comparator to get swap() to throw (a typical comparison predicate is
stateless, and its assignment is a no-op).
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925