C++核心准则C.101:赋予容器值语义
日期: 2020-03-21 分类: 个人收藏 388次阅读
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<string>& v) { Sorted_vector<string> v2 {v}; if (v != v2) cout << "insanity rules!\n"; // ... }
Enforcement(实施建议)
???
原文链接
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c101-give-a-container-value-semantics
觉得本文有帮助?欢迎点赞并分享给更多的人。
阅读更多更新文章,请关注微信公众号【面向对象思考】
除特别声明,本站所有文章均为原创,如需转载请以超级链接形式注明出处:SmartCat's Blog
上一篇: LeetCode365. 水壶问题
下一篇: Ubuntu18.04.1中安装gcc出现 “Command 'gcc' not found, but can be installed with: sudo apt install gcc”问题
精华推荐