c++include

At what point should I fight deep #include trees


I am currently working on a C++ project and am quite often using templates. Now I wonder if I should start worrying more about / cleaning up deep #include trees.

After removing not-needed includes, the code size after running the C preprocessor gcc -E on my .cpp files is:

Is there some standard if these are large/small line counts? At what point does it become worth being more aggressive in reducing the #includes?


Solution

  • It doesn't matter how many lines of code there are. What matters is whether you feel build times are tolerable. If it takes too long to compile, then you need to speed it up, for example by eliminating unneeded includes.

    But as long as you don't have a problem with build times, why bother worrying about whether you include too much?