I am including several STL headers such as list and vector in all my code files for my project. I know for my own headers that I should use include guards, but what about for this scenario when they aren’t defined by me?
Is it bad to include the same headers in every one of my files? Is there a performance penalty for each time it is included?
There is no performance cost. The standard headers have their own include guards, and all include guards are optimized by the preprocessor so the file isn’t actually reloaded each time.
Correctness and maintainability are always the first concern… how much compile time do you have to save to make up for work spent fixing things when you rearrange the files and get “undefined identifier” errors, or worse!
EDIT: There is no performance cost to multiply including the same standard headers from all your header files. There is some performance cost to including additional standard headers from a source file. The question is a bit ambiguous… but either way, the really expensive part of C++ compilation is usually template instantiation, not parsing the text.