SL.1: Use libraries wherever possible
SL.1:在任何可能的情况下使用已有库
Reason(原因)
Save time. Don't re-invent the wheel. Don't replicate the work of others. Benefit from other people's work when they make improvements. Help other people when you make improvements.
节约时间。不要重新发明车轮。不要重复其他人的工作。如果其他人进行了某种改善,我们可以从中获益。如果你进行了某种改善,帮助其他人获益。
SL.2: Prefer the standard library to other libraries
SL.2:标准库好于其他库
Reason(原因)
More people know the standard library. It is more likely to be stable, well-maintained, and widely available than your own code or most other libraries.
更多人知道标准库。标准库更有可能维持稳定,被很好地维护,比你自己写的代码或其他库具有更广泛的可用性。
SL.3: Do not add non-standard entities to namespace std
SL.3:不用选项std命名空间增加非标准实体
Reason(原因)
Adding to std might change the meaning of otherwise standards conforming code. Additions to std might clash with future versions of the standard.
将实体添加到std命名空间可能会改变其他遵守标准的代码的含义。增加到std命名空间中的实体有可能和标准库的将来版本发生冲突。
Example(示例)
???
Possible, but messy and likely to cause problems with platforms.
有可能,但是会混乱并可能引起平台相关问题。
SL.4: Use the standard library in a type-safe manner
SL.4:以类型安全的方式使用标准库
Reason(原因)
Because, obviously, breaking this rule can lead to undefined behavior, memory corruption, and all kinds of other bad errors.
因为,很显然,破坏这条规则会引发无定义行为,内存破坏或者各种其他类型的恶劣问题。
Note(注意)
This is a semi-philosophical meta-rule, which needs many supporting concrete rules. We need it as an umbrella for the more specific rules.
这是一条半哲学性质的准则,它需要很多具体准则的支持。我们需要将本规则当作其它具体规则的整体概括来看。
Summary of more specific rules:
更特定规则的归纳:
原文链接
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#sl1--use-libraries-wherever-possible