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

Rule:  OLC#002Checked automatically with code checker

Synopsis:Copy assignment operators shall be implemented with the swap idiom
Severity Level:4
Category:Object Life Cycle


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: