C++核心準(zhǔn)則C.101:賦予容器值語義?


C.101: Give a container value semantics
C.101:賦予容器值語義?


Reason(原因)?
Regular objects are simpler to think and reason about than irregular ones. Familiarity.
常規(guī)對象相比非常規(guī)對象更容易理解和思考。這是親和度方面的意義。

Note(注意)
If meaningful, make a container Regular (the concept). In particular, ensure that an object compares equal to its copy.
如果可以理解,讓容器符合常規(guī)(概念)。尤其要保證對象和它的拷貝比較時結(jié)果相等。

Example(示例)?
void?f(const?Sorted_vector&?v)
{
????Sorted_vector?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
覺得本文有幫助?請分享給更多人。
關(guān)注【面向?qū)ο笏伎肌枯p松學(xué)習(xí)每一天!
面向?qū)ο箝_發(fā),面向?qū)ο笏伎迹?/span>
評論
圖片
表情
