From 8145862109670926256
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,5cc796235bc9d4d8
X-Google-Attributes: gidf78e5,public
X-Google-Thread: 109fba,5cc796235bc9d4d8
X-Google-Attributes: gid109fba,public
X-Google-Thread: fc772,5cc796235bc9d4d8
X-Google-Attributes: gidfc772,public
From: Dave Abrahams <abrahams@motu.com>
Subject: Re: Article on exceptions in January C++ Report
Date: 1998/03/02
Message-ID: <6dcvqk$ogs@netlab.cs.rpi.edu>#1/1
X-Deja-AN: 329875494
References: <6cjhbk$ru6@netlab.cs.rpi.edu> <6cre6n$qbd@netlab.cs.rpi.edu> <6cu53k$918@netlab.cs.rpi.edu> <6d78m5$s4u@netlab.cs.rpi.edu>
X-Submission-Address: c++-submit@netlab.cs.rpi.edu
X-Original-Date: 1 Mar 1998 19:51:32 -0500
X-Approved-For-Group: herbs@cntc.com comp.lang.c++.moderated
Organization: Internet Maine/HarvardNet
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUANPoXw+EDnX0m9pzZAQFvNgGAju5vTQOMV4KaT7S4jODdaqkRoaShOt90 uanje1aIO3nuHLJ40sOL0dxtEPVSJOpF =RQPz
Newsgroups: comp.lang.c++.moderated,comp.std.c++,comp.lang.c++


Paul D. DeRocco wrote:

> greg wrote:
> >
> >  * swap() has no effects if it throws an exception,
>
> I think we pretty much proved, in this newsgroup a few months ago, that
> it is impossible to make swap safe for objects whose constructors might
> throw. In order to swap a with b, you have to copy a to temporary c,
> then b to a, then c to b; if the last one throws, you cannot expect to
> be able to move a back into b and put c back into a, so your stuck.

I'm not sure exactly what point you're trying to make, but ... the
decision in London referred to in Greg's post was regarding swap() used
on the standard containers. You can specialize swap so that it doesn't
have to use the objects' constructor. If you take a look at the
implementation of swap(vector<T>&, vector<T>&) in the SGI STL (just for
an example), you'll see a counterexample to any "proof" that swap can't
be safe for objects with throwing constructors.

  {Dave's quite right. See also the article in the Nov/Dev 1997 C++
Report. -hps}

-Dave


      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]



