views:

121

answers:

1

In my project several STL headers are used in different files. I read that, putting all these headers into a single header and using that header in my files will allow compilers to precompile the header which may lead into faster compile time.

If I understood it correctly, I need to write like the following.

// stl.hpp
#include <string>
#include <algorithm>
#include <vector>

Now include stl.hpp in all the files that needs access to STL. Is this correct?

Few of my files will be using only functionality from vector header file. But if I follow the above method, it will include unnecessary headers. Will this make any problem? Is there any code generated if I include a header file and not used anything from that?

Any help would be great!

A: 

Before attempting to speed-up you build by using pre-compiled headers, it's worth benchmarking/timing your existing builds to see if the speed-up will be worth the effort.

If you only have a few dozen files with #include <string> you may see no improvement. If you have 1000s of file, then it may be worth it.

See this article for more excellent info: www.cygnus-software.com

Kassini