Search code examples
c++stlcontainersstandards

Why C++ standard split container class into multiple header file?


I've been learning C++ for a while and getting confused about its container usage. If I want to use certain container I have to manually include them one by one. For example, if I want to use "vector" container I have to type #include "vector", and if I need "list" container later I have to add #include "list".

Why wouldn't C++ standard simply put every container class inside one header file, like #include "container", so that developers could care less about including them one by one?


Solution

  • Why wouldn't C++ standard simply put every container class inside one header file, like #include "container", so that developers could care less about including them one by one?

    Performance, specifically compile time performance. If you include everything, there is a lot of code that the compiler is going to have to deal with. If you only use 1% of everything, then 99% of the code the compiler is working with is useless to you and just wasting your time having the compiler deal with it.