Exception safety regarding swap() operation - what's so wrong with that?

Viewed 1854

I keep reading that swap() operation, like this for example:

template<class T>
void swap (T &a, T &b)
{
  T temp (a);
  a = b;
  b = temp;
}

is problematic when we are dealing with Exception-safety.

What's so wrong with it? Furthermore, how can we solve it?

3 Answers
Related