专业的编程技术博客社区

网站首页 > 博客文章 正文

C++核心准则C.101:赋予容器值语义?

baijin 2024-10-12 02:10:27 博客文章 13 ℃ 0 评论

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


觉得本文有帮助?请分享给更多人。

更多精彩文章欢迎关注微信公众号【面向对象思考】!

面向对象开发,面向对象思考!

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表