title: Why isn't the C++ standard library already pre-included in any C++ source?
body: <p>In C++ the standard library is wrapped in the <code>std</code> namespace and the programmer is not supposed to define anything inside that namespace. Of course the standard include files don't step on each other names inside the standard library (so it's never a problem to include a standard header).</p>
  
  <p>Then why isn't the whole standard library included by default instead of forcing programmers to write for example <code>#include &lt;vector&gt;</code> each time? This would <strong>also</strong> speed up compilation as the compilers could start with a pre-built symbol table for all the standard headers.</p>
  
  <p>Pre-including everything would also solve some portability problems: for example when you include <code>&lt;map&gt;</code> it's defined what symbols are taken into <code>std</code> namespace, but it's not guaranteed that other standard symbols are <strong>not</strong> loaded into it and for example you could end up (in theory) with <code>std::vector</code> also becoming available.</p>
  
  <p>It happens sometimes that a programmer forgets to include a standard header but the program compiles anyway because of an include dependence of the specific implementation. When moving the program to another environment (or just another version of the same compiler) the same source code could however stop compiling.</p>
  
  <p>From a technical point of view I can image a compiler just preloading (with <code>mmap</code>) an optimal perfect-hash symbol table for the standard library.
  This should be faster to do than loading and doing a C++ parse of even a single standard include file and should be able to provide faster lookup for <code>std::</code> names. This data would also be read-only (thus probably allowing a more compact representation and also shareable between multiple instances of the compiler).</p>
  
  <p>These are however just <strong>should</strong>s as I never implemented this.</p>
  
  <p>The only downside I see is that we C++ programmers would lose compilation coffee breaks and Stack Overflow visits :-)</p>
  
  <h2>EDIT</h2>
  
  <p>Just to clarify the <strong>main</strong> advantage I see is for the programmers that today, despite the C++ standard library being a single monolithic namespace, are required to know which sub-part (include file) contains which function/class. To add insult to injury when they make a mistake and forget an include file still the code may compile or not depending on the implementation (thus leading to non-portable programs).</p>