Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Vector exception safety

Reply
Thread Tools

Vector exception safety

 
 
Aarti
Guest
Posts: n/a
 
      07-20-2007
I was reading about exception safety in vectors and came across a
staement that says

The clear operation of vector guarantees a nothrow provided the copy
and assignment operator do not throw an exception.

Now clear just deletes all the elements of a vector. What has copy
and assignment operator got to do with it?
Can anyone please shed some light.

Regards

 
Reply With Quote
 
 
 
 
Michael DOUBEZ
Guest
Posts: n/a
 
      07-20-2007
Aarti a écrit :
> I was reading about exception safety in vectors and came across a
> staement that says
>
> The clear operation of vector guarantees a nothrow provided the copy
> and assignment operator do not throw an exception.
>
> Now clear just deletes all the elements of a vector. What has copy
> and assignment operator got to do with it?
> Can anyone please shed some light.


My only guess is that clear() is equivalent to erase(begin(),end()) and
erase() is nothrow provided the copy and assignment operator do not
throw an exception.

But since we erase from begin() to end(), there wouldn't be any
assignement or copy. I wouldn't expect clear() it to throw.

Where did you read it ?

Michael
 
Reply With Quote
 
 
 
 
Aarti
Guest
Posts: n/a
 
      07-21-2007
On Jul 20, 2:32 am, Michael DOUBEZ <(E-Mail Removed)> wrote:
> Aarti a écrit :
>
> > I was reading about exception safety in vectors and came across a
> > staement that says

>
> > The clear operation of vector guarantees a nothrow provided the copy
> > and assignment operator do not throw an exception.

>
> > Now clear just deletes all the elements of a vector. What has copy
> > and assignment operator got to do with it?
> > Can anyone please shed some light.

>
> My only guess is that clear() is equivalent to erase(begin(),end()) and
> erase() is nothrow provided the copy and assignment operator do not
> throw an exception.
>
> But since we erase from begin() to end(), there wouldn't be any
> assignement or copy. I wouldn't expect clear() it to throw.
>
> Where did you read it ?
>
> Michael


Hmm. Strostup memtions it in Exception safety of STLs

 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      07-22-2007
On Jul 20, 11:32 am, Michael DOUBEZ <(E-Mail Removed)> wrote:
> Aarti a écrit :


> > I was reading about exception safety in vectors and came across a
> > staement that says


> > The clear operation of vector guarantees a nothrow provided the copy
> > and assignment operator do not throw an exception.


> > Now clear just deletes all the elements of a vector. What has copy
> > and assignment operator got to do with it?
> > Can anyone please shed some light.


> My only guess is that clear() is equivalent to erase(begin(),end()) and
> erase() is nothrow provided the copy and assignment operator do not
> throw an exception.


Exactly. For whatever reasons, the standard makes no promess
with regards to clear(), saying simply that clear() is an exact
equivalent of erase(begin(),end()). And so the only guarantees
are those of erase, and there's no special case in erase for the
case where all of the elements are being erased. (In fact, in
std::vector, you could probably make a no throw guarantee for
erase any time the second iterator is end().)

> But since we erase from begin() to end(), there wouldn't be any
> assignement or copy. I wouldn't expect clear() it to throw.


In practice, nor would I.

I suspect that if you asked the committee nicely, specifying the
exact change in the wording, and if they could find time (far
from sure), they'd be willinig to make the change.

--
James Kanze (Gabi Software) email: http://www.velocityreviews.com/forums/(E-Mail Removed)
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
const vector<A> vs vector<const A> vs const vector<const A> Javier C++ 2 09-04-2007 08:46 PM
Initializing vector<vector<int> > and other vector questions... pmatos C++ 6 04-26-2007 05:39 PM
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
Free memory allocate by a STL vector, vector of vector, map of vector Allerdyce.John@gmail.com C++ 8 02-18-2006 12:48 AM
how the vector is created, how to pass vector to webservices method apachesoap:Vector Rushikesh Joshi Perl Misc 0 07-10-2004 01:04 PM



Advertisments