C++核心准则C.101:赋予容器值语义
面向对象思考
共 467字,需浏览 1分钟
·
2020-01-26 23:22
C.101: Give a container value semantics
C.101:赋予容器值语义
Reason(原因)
Regular objects are simpler to think and reason about than irregular ones. Familiarity.
常规对象相比非常规对象更容易理解和思考。这是亲和度方面的意义。
Note(注意)
If meaningful, make a container Regular (the concept). In particular, ensure that an object compares equal to its copy.
如果可以理解,让容器符合常规(概念)。尤其要保证对象和它的拷贝比较时结果相等。
Example(示例)
void f(const Sorted_vector& v)
{
Sorted_vectorv2 {v};
if (v != v2)
cout << "insanity rules!\n";
// ...
}
Enforcement(实施建议)
???
原文链接
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c101-give-a-container-value-semantics
觉得本文有帮助?请分享给更多人。
关注【面向对象思考】轻松学习每一天!
面向对象开发,面向对象思考!
评论