I want to browse the source code of gnu implementation of C++ standard libraries — header files as well as the implementation.
I have landed myself into:
http://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-4.4/index.html
My first step was to look header file at:
http://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-4.4/a01376.html
My question is that as per my understanding the typedeffed string sth like:
typedef basic_string string;
should have been present in string header, but I don’t see one here.
Questions:
–in which file is the definition of string symbol?
–I see that string header file includes lot many headers and if the typedeffed sring symbol is defined in one of these internal headers, is there a search bar something on this site thru which I can reach to the definition of a symbol straightway. (in case someone has already browsed stuff from this site before)
Thanks,
Jagrati
A lot of libstdc++ is implemented using only headers, but some parts of the STL, like
std::basic_string, have compiled implementations.The declaration of template
std::basic_stringis located in/usr/include/c++/4.4.4/bits/basic_string.h(replace ‘4.4.4’ withg++ -dumpversion) and the implementation is in/usr/include/c++/4.4.4/bits/basic_string.tcc. The actualtypedefofstd::string,std::wstring, etc. is in.../bits/stringfwd.h. If you needed to instantiatestd::basic_stringwith other template parameters, for example, then you do something like:The way that libstdc++ implements sets and maps (header-only) is kind of interesting, but also very complex because it uses a custom red-black tree implementation (
_Rb_tree).The libstdc++ implementation of
std::vector(also header-only) is more self-contained, so it’s worth a glance in/usr/include/c++/4.4.4/bits/stl_vector.hto give you an idea of the internals of libstdc++. Another interesting file is.../bits/stl_algo.h, which contains the definitions of STL algorithms.Note: On Windows with MinGW, you’ll find the libstdc++ headers in
lib\gcc\mingw32\4.4.0\include\c++\bitsof your MinGW installation, replacing ‘4.4.0’ withg++ -dumpversion.