I've recently come to appreciate the copy-and-swap idiom, and have been using it to implement copy-assignment for any class which manages a resource. So it got me thinking about Standard Library types: does the standard guarantee exception-safe behavior?
For example, consider a class that contains one std::string
data member. Ordinarily, I wouldn't have implemented my own copy-assignement, etc., but is this safe? Does the standard guarantee that the std::string
data member is left unchanged if the copy-assignment fails? Would it be beneficial to implement copy-and-swap in this case -- or is that just going too far?