> the self-assignment test does not work well in class hierarchies either,
> even with use of boost::addressof().
it is unlikely that using value semantics on object-oriented types is something that people would want to do. however, the self-assignment test would work perfectly as long as the overloaded assignment operator is ThreeD& ThreeD::operator= ( const ThreeD& that ) ;
that
would be a reference to the anonymous base class sub-object (of type ThreeD) and the boost::addressof() would return the address of the ThreeD sub-object.
the 'make temporary copy and swap' technique does not work at all in class hierarchies when the base class ThreeD is abstract.
> difficult to implement an exception-safe assignment operator without creating a
> temporary copy - of either the object itself, or (at a minimum) of the data it contains.
> Doing a self-assignment test - even if it works - does not change that.
not necessarily if the class is designed with exception-safety in mind. for example,
struct A
{
public:
// ...
private: std::list< std::string > strlist ;
};
exception-safe assignment operator can be written without creating a temporary copy of the strings.