TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
C++ Coding Standard
Search

Rule:  OLC#002Checked automatically with code checker

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