How do you maintain the #include statements in your C or C++ project? It seems almost inevitable that eventually the set of include statements in a file is either insufficie
Detecting superfluous includes has already been discussed in this question.
I'm not aware of any tools to help detect insufficient-but-happens-to-work includes, but good coding conventions can help here. For example, the Google C++ Style Guide mandates the following, with the goal of reducing hidden dependencies:
In dir/foo.cc
, whose main purpose is to implement or test the stuff in dir2/foo2.h
, order your includes as follows:
dir2/foo2.h
(preferred location — see details below).