c++ - Header inclusion optimization -
Is there an automatic way to include header files in C ++, so that the compile time improves? With the word "automatic" I mean a tool or program. Is it possible to find out which header files are obsolete (e.g., highlighted functionality is not used)?
Edit : Adding a header to each "is only important once, but there is a way to change the contents of the files so that it often uses" functionality " Can be included in the specific and the less frequently used functionality is included in the other? Am I asking too much? Unfortunately, we are talking about thousands of files about an existing code base. Or is this really a refactoring tool that I'm really asking?
Thank you.
Update
I use what you really want "rather than the minimum set of headers." IWYU "means that as much as possible Announce and include the header, which directly announces the symbols you use. You can not fail to clean a file IWYU because it can no longer be compiled when this happens, you have to find and add missing headers. However, if every file is IWYU, your compilers will be cleaned, even if you have to add a header. Ccasionally Your headings will not be more to mention.
According to my previous answer, it is technically possible to include less headers than required for IWYU, but it is usually a waste of time.
Some issues:
-
Changing the included header files can change behavior, and still compile the file. Especially an example, if you have defined your own
std :: swap
in a different header file, you can remove that header and your code will still be the defaultstd :: swap
will be compiled using the implementation, however,std :: swap
may be: disabled, causes runtime error, or worse produce novel incorrect logic. -
Sometimes a header file works as a documented document, for example,
std :: foreach
, often& lt ; Vector & gt; It is enough to compile it to include
. Code more#include & lt; Algorithm & gt;
. -
With more meaningful, at least the compilation set can not be portable, between compiler or compiler versions. Again, using the
std :: foreach
example, there is no guarantee thatstd :: foreach
by& lt; Vector & gt; Will be provided by
. -
Of these, the compilation can not be affected in any way from time to time in the minimum set. Visual Studio and GCC support are included on the basis of the
#pragma one time
incomplete non-existent performance and at least GCC has been optimized to process the preprocessor, in which the guard Very fast (fast as the#pragma
) has been included in.
Comments
Post a Comment