Where are the headers of the C++ standard library

Thomas picture Thomas · Jul 12, 2012 · Viewed 64.6k times · Source

I wonder where on my file system I find the headers of the C++ Standard library. In particular I am looking for the definition of the vector template. I searched in /usr/include/ and various subdirectories. I also tried 'locate vector.h' which brought up many implementations of vectors, but not the standard one. What am I missing? (The distribution is Gentoo)

Background: I'm profiling a library that iterates over vector's most of the time and gprof shows that most of the time is spent in

std::vector<int, std::allocator<int> >::_M_insert_aux(
  __gnu_cxx::__normal_iterator<int*, std::vector<
      int, std::allocator<int> > >, int const&)

Probably this is what happens internally on a std::vector::push_back, but I'm not sure.

Answer

Mike Seymour picture Mike Seymour · Jul 12, 2012

GCC typically has the standard C++ headers installed in /usr/include/c++/<version>/. You can run gcc -v to find out which version you have installed.

At least in my version, there is no vector.h; the public header is just vector (with no extension), and most of the implementation is in bits/stl_vector.h.

That's the case on my Ubuntu distribution; your distribution may differ.