Skip to content

Assignment operator takes a value parameter #2279

@lijh8

Description

@lijh8

On rule of three / five page on cppreference, this assignment operator with a value parameter can replace assignment with both reference and rvalue reference parameter. This makes it rule of four. Can this be mentioned on the core guidelines if it is legal?

rule_of_five& operator=(rule_of_five other) noexcept
{
    std::swap(cstring, other.cstring);
    return *this;
}

cppreference is the only place which has a complete and correct example of rule of five. Such an example is not seen in books like C++ Primer, The C++ Programming Language. Can future editions of these book include a complete and correct example of rule of five. Is not this the core of c++?

ref:

https://en.cppreference.com/w/cpp/language/rule_of_three.html ,

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cctor-constructors-assignments-and-destructors ,
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-five ,
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-copy-assignment ,
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-move-assignment ,

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions