Does Whole support the strong exception safety guarantee?
The default constructor will be exception safe if the copy constructor of arg::body_part_ptr<> is. (If you check the documentation you’ll find this to be the case.)
The Whole::swap() member function will be exception safe if std::swap() doesn’t throw exceptions…The default implementation of std::swap() uses copy construction and assignment. This is good enough for base types and simple value based classes but if used with a type for which either of these throw then std::swap() will (1) throw exceptions and (2) will violate the strong exception safety guarantee.
The authors of the standard library have addressed this issue by providing partial specialisations of std::swap() for the STL containers that call a non-throwing swap() member function on the container. I’ve done the same for arg::body_part_ptr<>.…So the Whole::swap() member function is exception safe and also conforms to the “doesn’t throw” requirement that allows Whole to be used within other strongly exception safe classes.
The assignment operator will be exception safe if both the copy construction and the Whole::swap() member function are.
There is just one more thing that ought to be done to make Whole a good citizen in the exception safe world. Any suggestions?