I am working on a large project that uses the STL and have a question about your preferred way to organise your STL #includes
.
- Do you prefer to #include each header in the source file it is used. For example, if both
foo.cpp
andbar.cpp
requirestd::string
, then both will#include <string>
. - Do you prefer to have a single header file that includes all the STL headers your project uses (i.e. add them to the MS 'stdafx.h' pre-compiled header).
The advantage of the first method is that the .cpp file is an independent unit and can be used in a different project without having to worry that you're missing a #include
. The advantages of the second method is that you can take use your compilers pre-compiled header support plus you can wrap STL #includes
in pragmas
that disable some warnings (for example, some Boost headers will cause warnings when compiling at level 4).
Which do you prefer to use?