GotW #4 Solution: Class Mechanics -- Herb Sutter
The solution to GotW #4 is now available:
GotW #4 Solution: Class Mechanics (updated for C++11/14)
by Herb Sutter
From the article:
... To see why, consider the following canonical forms for howoperator+=andoperator+should normally be implemented for some typeT.T& T::operator+=( const T& other ) { //... return *this; }
T operator+( T a, const T& b ) { a += b; return a; }Did you notice that one parameter is passed by value, and one by reference? That’s because if you’re going to copy from a parameter anyway, it’s often better to pass it by value, which will naturally enable a move operation if the caller passes a temporary object such as in expressions like
(val1 * val2) + val3. We’ll see more on parameter passing in a future GotW. ...
.

Note: This updated working draft contains all of the updates approved at the Bristol ISO C++ meeting to make this the C++14 Committee Draft. Today our project editor Stefanus Du Toit, wth the kind help of Jonathan Wakely and our editorial committee of Daniel Kruegler, Alisdair Meredith, Mike Miller, and Richard Smith, finished applying and verifying the updates voted in at Bristol. This document has now been transmitted to SC22 for circulation for C++14's primary international comment ballot.
The C++Now 2013 conference is still in flight, but presentation materials are being made available online as the conference progresses. You can find them here in their GitHub repository:
