Given Jon Kalb's strongly exception-safe code to solve the Cargill Widget example, what prevents the compiler from re-organizing the operations and thus making the code not strongly exception-safe?
#include <algorithm> // std::swap
template< typename T1, typename T2 >
class Cargill_Widget
{
public:
Cargill_Widget& operator=( Cargill_Widget const& r_other )
{
using std::swap;
T1 temp_t1( r_other.m_t1 ); // may throw
T2 temp_t2( r_other.m_t2 ); // may throw
/* The strong exception-safety line */
swap( m_t1, temp_t1 ); // no throw
swap( m_t2, temp_t2 ); // no throw
return *this;
}
private:
T1 m_t1;
T2 m_t2;
};
Is it the "the compiler can't change the observable behaviour" rule?
Reference:
- Jon Kalb's "Exception-Safe Code" Presentation Slides: http://www.exceptionsafecode.com/slides/esc.pdf