In the C++ Google Style Guide's section on headers, the first line says:
Use standard order for readability and to avoid hidden dependencies: Related header, C library, C++ library, other libraries' .h, your project's .h.
But that appears backwards to me because project's headers are likely to be dependent on system headers whereas system headers are obviously not likely to be dependent on project headers. Simplifying the example given in the guide, we get the following #include
lines for X.cpp
that is dependent on X.h
, the standard header <vector>
and another file in the project's codebase, A.h
:
#include "X.h"
#include <vector>
#include "other/module/A.h"
If A.h
is dependent on <vector>
, the style's order hides the problem. If the headers were included in the order of most related to least related the problem would be exposed.
What am I missing? Perhaps the counter-argument is that this problem would be exposed when A.cpp
gets compiled but that argument doesn't stand if there is no A.cpp
to start with (i.e. A.h
is header-only).