c++ vector source code

会有一股神秘感。 提交于 2019-12-04 03:34:22
Steve Townsend

There is no 'standard' vector - the standard defines behaviour and interface (and some implementation details, such as contiguous storage) but the code is a matter for compiler writers to determine.

Your compiler should have its own <vector> header file, have you checked for this on your build include path? Once you find that you should also see the other STL containers in their respective headers. The list for Microsoft Visual C++ is here, including some that are proprietary, so watch out for that per the below sample disclaimer:

In Visual C++ .NET 2003, members of the <hash_map> and <hash_set> header files are no longer in the std namespace, but rather have been moved into the stdext namespace. See stdext Namespace for more information.

On my installation of Visual C++ Express 2010, they are in this folder:

c:\program files\microsoft visual Studio 10.0\vc\include

Different runtime has different implementation.

But I guess this is what you want, the widely used gcc implementation: https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/std/vector

It is the main header file, and the implementation is in https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/bits/stl_vector.h and https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/bits/stl_bvector.h

It use MACRO to make the code run in good performance and fit in variable situation, but make it hard to read, wish you good luck.

Most if not all of the std::vector source code should be contained in the <vector> header itself.

The standard library containers are all class templates and as such, their definitions and the definitions of all of their member functions are contained in their respective headers.

Note that there is no One True Implementation of any of the containers; each C++ Standard Library implementation is free to implement each container as it sees fit, so long as it meets the requirements for the container.

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