C.63: Make move assignment non-virtual, take the parameter by &&, and return by non-const &
C.63:保证移动赋值运算符为非虚函数,参数类型为右值引用,返回值为常量引用类型
Reason(原因)
It is simple and efficient.
这样做简单且高效。
See(参见):
The rule for copy-assignment.
拷贝赋值规则。
相关链接:
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rc-copy-assignment
Enforcement(实施建议)
Equivalent to what is done for copy-assignment.
和拷贝赋值的情况时所做的相同。
-
(Simple) An assignment operator should not be virtual. Here be dragons!
(简单)赋值运算符不应该是虚函数。那样做很危险。
-
(Simple) An assignment operator should return T& to enable chaining, not alternatives like const T& which interfere with composability and putting objects in containers.
(简单)赋值运算符应该返回T&,这样才能实现连续赋值。不要改成类似const T&的类型,这样会影响组装性并妨碍将对象放进容器中。
-
(Moderate) A move assignment operator should (implicitly or explicitly) invoke all base and member move assignment operators.
(中等)移动赋值运算符应该(隐式或显式)调用所有的基类和成员的移动赋值运算符。
原文链接
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c63-make-move-assignment-non-virtual-take-the-parameter-by--and-return-by-non-const-
觉得本文有帮助?欢迎点赞并分享给更多的人。
阅读更多更新文章,请关注微信公众号【面向对象思考】