C++: Stream Operators Assignment Operators & Copy-and-Swap
The stream insertion and extraction operators are often overloaded because they provide a convenient way to read objects in and write objects out to standard IO. The copy assignment operator is even more crucial because of how important it is in correctly freeing up resources held by an object. In this course learn how to implement the correct overloads of the insertion and extraction operators and why these are invariably implemented as non-member functions. Then move on to correctly overloading the copy assignment operator and using standard formats to ensure that resource cleanup occurs exactly once. Finally find out how the copy-and-swap idiom provides a way to use the std::swap function to implement the copy assignment operator in a manner that is exception-safe. This idiom leads to an elegant implementation that is not only less complex but also more robust.