

SF.4:在其他声明之前include .h文件
Minimize context dependencies and increase readability.
最小化上下文依赖性并提高可读性。
Example(示例)
#include <vector>
#include <algorithm>
#include <string>
// ... my code here ...#include <vector>
// ... my code here ...
#include <algorithm>
#include <string>This applies to both .h and .cpp files.
本规则.h文件和.cpp文件都适用。
Note(注意)
There is an argument for insulating code from declarations and macros in header files by #including headers after the code we want to protect (as in the example labeled "bad"). However
关于在头文件中隔离代码和声明/宏的方式存在其他观点,这种观点建议在需要保护的代码之后include头文件(就像我们注明反面示例的代码)。然而:
See also(参见):
Enforcement(实施建议)
Easy.
容易。
原文链接
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#sf4-include-h-files-before-other-declarations-in-a-file