Standard C++ libraries headers on gnu gcc site

前提是你 提交于 2019-12-07 02:13:25

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!