如何获取 C++ 标准库的源码

获取 C++ 标准库主要有两种途径: 从 C++ 编译器的安装位置(Your C++ compiler installation location)和直接查看或下载网上开源代码(Online open source codes). 具体如下:

C++编译器的安装位置(Your C++ compiler installation location)

Windows OS

Visual Studio — X:\Microsoft Visual Studio 9.0\VC\crt\src; X:\Program files (x86)\Microsoft Visual Studio 14.0\VC\include\; X:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\crt\src
Note,
1) You even don't have to install Visual Studio to explore Microsoft implementation. Online compilers can help: rextester.com/NRP17506
2) In Visual Studio if you interesting in concrete(specific) STL-element implementation (for example, any function), right click on its mention in your code and chose "Go to Definition" in context menu. (Or place cursor on this mention and push "F12")

Linux/Unix

gcc — /usr/include/c++/; /usr/lib/gcc/$CTARGET/$VERSION/include/g++-v4/
Note, `locate iostream` is a good solution to find the installation location.
 

网上开源代码(Online open source codes)

  • libc++

libc++ — the C++ standard library of LLVM project.
libc++ is an implementation of the C++ standard library, targeting C++11, C++14 and above.
http://libcxx.llvm.org/
https://github.com/llvm/llvm-project/tree/master/libcxx/

 

  • gcc

GCC, the GNU Compiler Collection
The GNU project is Free and Open Source software, and contains an implementation of the C++ standard library.
https://github.com/gcc-mirror/gcc/tree/master/libstdc%2B%2B-v3
https://github.com/gcc-mirror/gcc

 

  • Apache stdcxx

Apache C++ Standard Library.
The Apache C++ Standard Library project (code name stdcxx, pronounced "standard C++ library", not S-T-D-C-X-X) is a collection of algorithms, containers, iterators, and other fundamental components of every piece of software, implemented as C++ classes, templates, and functions essential for writing C++ programs.
http://stdcxx.apache.org/
http://svn.apache.org/repos/asf/stdcxx/

 

  • STLport

Multiplatform C++ Standard Library (STL implementation). Many compilers and operational environments supported. Standard (ISO/IEC 14882) compliance. Maximum efficiency. Exception and thread safety. Debug mode.
http://www.stlport.org/
https://sourceforge.net/projects/stlport/

  

  • SGI STL

SGI(Silicon Graphics Computer Systems, Inc.) implement STL(C++ Standard Libirary).
https://github.com/karottc/sgi-stl

 

  • MSVC STL

Microsoft's C++ Standard Library
MSVC's implementation of the C++ Standard Library. https://github.com/microsoft/STL

 

参考资料

[1] https://stackoverflow.com/questions/2004212/where-to-get-the-source-code-for-the-c-standard-library 

你可能感兴趣的:(如何获取 C++ 标准库的源码)