This rule is Obsolete | |
Synopsis: | Copy assignment operators shall be implemented with the swap idiom |
Language: | C++ |
Severity Level: | 4 |
Category: | Object Life Cycle |
Description: |
The swap idiom is considered to be the most clear and efficient implementation of the copy assignment operator. The implementation of the copy assignment operator is as follows: MyClass& operator=(MyClass other) { swap(*this, other); return *this; } Important remark. If the copy assignment operator takes a const reference as argument the swap idiom can't be used. |
Literature References: |
StackOverflow |