comp.lang.ada
 help / color / mirror / Atom feed
* Safety of the Booch Ada 95 Components
@ 1999-12-10  0:00 Harry Erwin
  1999-12-10  0:00 ` Simon Wright
                   ` (2 more replies)
  0 siblings, 3 replies; 29+ messages in thread
From: Harry Erwin @ 1999-12-10  0:00 UTC (permalink / raw)


In C++, the equate operation for a container class C<T> is preferably
defined as follows (Sutter, Exceptional C++, Addison-Wesley, 2000):

template <typename T>
C<T>& operator=(const C<T>& c)
{
    if(&c == this) return *this; // not required; done for efficiency
    C temp(c); // uses the copy constructor, may throw
    swap(temp, *this); // swaps the guts of this container with
                       // temp. May not throw.
    return *this; // May not throw.
} // the destructor for temp releases the memory originally in this
  // container, and destructors may not throw

This is strongly exception-safe and exception-neutral, since only the
copy constructor can throw, and that occurs before the guts are swapped.
Hence the container remains useable, and no objects are lost from it.
Now I've been looking at the Booch components for Ada 95, and have
noticed that the Copy function typically starts by clearing the To
container. That immediately implies that they are not exception-safe,
but I'm concerned that they may not be safe under self-assignment as
well. Is there something about the Ada 95 standard that guarantees that
there will be no aliasing of container args?

-- 
Harry Erwin, PhD, <http://mason.gmu.edu/~herwin>




^ permalink raw reply	[flat|nested] 29+ messages in thread

end of thread, other threads:[~1999-12-17  0:00 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-12-10  0:00 Safety of the Booch Ada 95 Components Harry Erwin
1999-12-10  0:00 ` Simon Wright
1999-12-12  0:00   ` Simon Wright
1999-12-12  0:00     ` Matthew Heaney
1999-12-12  0:00   ` Harry Erwin
1999-12-13  0:00     ` Simon Wright
1999-12-10  0:00 ` Matthew Heaney
1999-12-10  0:00   ` Hyman Rosen
1999-12-10  0:00     ` Matthew Heaney
1999-12-11  0:00       ` Harry Erwin
1999-12-12  0:00         ` Robert Dewar
1999-12-12  0:00           ` Harry Erwin
1999-12-13  0:00           ` Kent Paul Dolan
1999-12-13  0:00             ` Simon Wright
1999-12-13  0:00             ` Ted Dennison
1999-12-13  0:00             ` Robert I. Eachus
1999-12-13  0:00       ` Hyman Rosen
1999-12-13  0:00         ` Robert I. Eachus
1999-12-14  0:00           ` Simon Wright
1999-12-15  0:00             ` Harry Erwin
1999-12-15  0:00             ` Mats Weber
1999-12-17  0:00               ` Simon Wright
1999-12-14  0:00         ` Matthew Heaney
1999-12-10  0:00     ` Harry Erwin
1999-12-10  0:00   ` Harry Erwin
1999-12-12  0:00     ` Simon Wright
1999-12-12  0:00       ` Harry Erwin
1999-12-13  0:00         ` Simon Wright
1999-12-13  0:00 ` Tucker Taft

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox