What does HackerNews think of include-what-you-use?
A tool for use with clang to analyze #includes in C and C++ source files
https://github.com/include-what-you-use/include-what-you-use
> * Forward-declare as much as you can. Forward type declarations mean that the compiler doesn't need to process all of `Foo` when it sees `Foo&` or `Foo`.
I've found the include-what-you-use (IWYU) tool [1][2] can help immensely with automating this process, especially on large code-bases.
It uses LLVM/Clang to analyze a .cpp file / translation unit and produces the minimal subset of exactly which includes are necessary and what types can be forward declared.
[1] https://include-what-you-use.org/
[2] https://github.com/include-what-you-use/include-what-you-use
Fingers crossed.
If this is in third-party libraries, you can use IWYU Mappings [3] to map the "private" headers (usually the transitive include) to the public interface. An example that I use for the PEGTL library [4].
[1]: https://github.com/include-what-you-use/include-what-you-use...
[2]: https://github.com/anand-bala/signal-temporal-logic/blob/800...
[3]: https://github.com/include-what-you-use/include-what-you-use...
[4]: https://github.com/anand-bala/signal-temporal-logic/blob/800...
I've also recently been making libraries I write compatible with users that run IWYU by annotating all public headers with IWYU pragma comments that export symbols/transitive includes correctly, etc.
[1]: https://github.com/include-what-you-use/include-what-you-use...
[2]: https://github.com/include-what-you-use/include-what-you-use...
> CAVEAT
> This is alpha quality software -- at best (as of July 2018). It was originally written to work specifically in the Google source tree, and may make assumptions, or have gaps, that are immediately and embarrassingly evident in other types of code.
> While we work to get IWYU quality up, we will be stinting new features, and will prioritize reported bugs along with the many existing, known bugs. The best chance of getting a problem fixed is to submit a patch that fixes it (along with a test case that verifies the fix)!
https://github.com/include-what-you-use/include-what-you-use...
Further useful docs:
Why Include What You Use? https://github.com/include-what-you-use/include-what-you-use...
What Is A Use? https://github.com/include-what-you-use/include-what-you-use...
Why Include What You Use Is Difficult https://github.com/include-what-you-use/include-what-you-use...
Sometimes it gets some things wrong, so you have these escape hatches to control it: https://github.com/include-what-you-use/include-what-you-use...