-3

Is it a good and common practice to concentrate for example all STL includes within one header file?

// mystlheader.h
//My STL Headerfile 
#pragma once

#include <vector>
#include <list>
#include <optional>

And if I need a std::vector, std::list or any other STL stuff in my project I include only this file (#include "mystlheader.h").

Are there any drawbacks like header file pollution?

user5580578
  • 465
  • 3
  • 12
  • 4
    ***Is it a good and common practice to concentrate for example all STL includes within one header file?*** No it is a very bad practice. – drescherjm Jul 02 '18 at 17:49
  • Some compilers already have a similar header file with it, which makes this question very relevant: [Why should I not #include ?](http://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h) – Some programmer dude Jul 02 '18 at 17:50
  • It depends, for example, it could be a good practice if this is a part of precompiled headers. – SergeyA Jul 02 '18 at 17:51
  • The duplicate has no mentioning of precompiled headers, so I am not in agreement with the closure. – SergeyA Jul 02 '18 at 17:53
  • And since some mentione *pre-compiled headers*, even if you have and use those including headers that aren't needed still will have an impact on build time. Much less than without pre-compiled headers, but it's still a little. – Some programmer dude Jul 02 '18 at 17:59
  • BTW, there is a project here that helps you do the reverse: https://include-what-you-use.org/ – drescherjm Jul 02 '18 at 18:00

1 Answers1

3

Your compile time will increase due to so many header files. Use only the files that are needed in a cpp file.

Rao Nagaraj
  • 166
  • 4