struct Circle
{
// ...
Circle& operator= ( const Circle& that )
{
assert( is_valid() && that.is_valid() ) ; // sanity check
/******************** this is the long-winded way of doing it
if( this != std::addressof(that) ) // if not trivial self assignment
// if the object is not being assigned to itself
{
// we are ok if this throws; assignment fails, and the object is left unchanged
const auto temp_ptr = new std::string(*that.name) ;
delete name ; // this will never fail
name = temp_ptr ; // this will never fail
}
******************************************************/
*name = *that.name ; // short, sweet and correct
// if this throws, std::string would do the right thing
assert( is_valid() ) ;
return *this ;
}
// ...
std::string* name ; // invariant: not null
bool is_valid() const
{
// return true if the object is in a valid state
return name != nullptr ;
}
};