Directly Include Referenced Files¶
The “Directly Include Referenced Files” feature is a powerful tool that can save C++ developers a lot of time and effort in the coding process. This feature automatically adds include directives to a file under consideration, based on the referenced declarations contained within it. This means that all files containing those referenced declarations will be included directly, without the need for manual intervention. The idea behind this feature was first proposed by John Lakos, a well-known author and software engineer, in his book Large-Scale C++ Software Design (5th guidline) Lakos argues that including header files directly can lead to faster and more efficient compilation times, as well as improved code readability and maintainability. By using the “Directly Include Referenced Files” feature, developers can ensure that all necessary header files are included directly in their code, without the risk of missing important dependencies. This can help to reduce the likelihood of compile-time errors and improve the overall quality of the codebase. Overall, the “Directly Include Referenced Files” feature is a valuable addition to any C++ developer’s toolkit, and can help to streamline the coding process while improving code quality and maintainability.Example¶
/* main.cpp */
#include "Y.h"
int main() {
X x;
return 0;
}
/* Y.h */
#include "X.h"
/* more code */
/* X.h */
class X { };
/* ... */
Here, the Includator makes the proposal to include file X.h directly into main.cpp independent of other, used or unused, types in Y.h.