Search This Blog

Monday, May 16, 2011

ExceptionalC++ Fun: 13. Exception Safe code. use swap

use swap. if something is wrong, it's contained in the temp. only swap the good temp if and only if we are totally ready.
Stack& operator=(const Stack& other)
  Stack temp(other); // does all the work
  Swap( temp );      // this can't throw
  return *this;

No comments: