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_string
is located in /usr/include/c++/4.4.4/bits/basic_string.h
(replace '4.4.4' with g++ -dumpversion
) and the implementation is in /usr/include/c++/4.4.4/bits/basic_string.tcc
. The actual typedef
of std::string
, std::wstring
, etc. is in .../bits/stringfwd.h
. If you needed to instantiate std::basic_string
with other template parameters, for example, then you do something like:
#include <bits/basic_string.tcc>
template class std::basic_string<long>;
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.h
to 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++\\bits
of your MinGW installation, replacing '4.4.0' with g++ -dumpversion
.
You can find what you need directly in /usr/include/c++
: since the standard tag library is composed by templates, most of the code it's placed directly in header files.
Also I tried to read them once, but trust me: you don't want to do it. :) Seriously, it's a bit messy.
A quick grep told me that typedef basic_string<char> string
is in bits/stringfwd.h
. I'm using gcc 4.5.0
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.