简体   繁体   English

c ++矢量源代码

[英]c++ vector source code

I am trying to get the vector source code to see how the standard std or stl vector is implemented. 我试图获取矢量源代码,看看如何实现标准的std或stl向量。

This is for learning purpose. 这是出于学习目的。 Now the question is where can i find the source code. 现在问题是我在哪里可以找到源代码。 Even source code of other C++ Container also helpful. 甚至其他C ++容器的源代码也很有帮助。

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? 您的编译器应该有自己的<vector>头文件,您是否在构建包含路径上检查了这个? Once you find that you should also see the other STL containers in their respective headers. 一旦发现您还应该在各自的标题中看到其他STL容器。 The list for Microsoft Visual C++ is here , including some that are proprietary, so watch out for that per the below sample disclaimer: Microsoft Visual C ++列表在这里 ,包括一些专有的,所以请注意以下示例免责声明:

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. 在Visual C ++ .NET 2003中, <hash_map><hash_set>头文件的成员不再位于std命名空间中,而是已移入stdext命名空间。 See stdext Namespace for more information. 有关更多信息,请参见stdext命名空间。

On my installation of Visual C++ Express 2010, they are in this folder: 在我安装的Visual C ++ Express 2010上,它们位于以下文件夹中:

c:\\program files\\microsoft visual Studio 10.0\\vc\\include 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 但我想这就是你想要的,广泛使用的gcc实现: 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 它是主头文件,实现位于https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/bits/stl_vector.hhttps:// 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. 它使用MACRO使代码运行良好,适应各种情况,但是难以阅读,祝你好运。

您的位置是: http//www.sgi.com/tech/stl/download.html

Most if not all of the std::vector source code should be contained in the <vector> header itself. 大多数(如果不是全部) std::vector源代码应该包含在<vector>标头本身中。

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; 请注意,任何容器都没有One True Implementation; 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. 每个C ++标准库实现都可以自由地实现每个容器,只要它满足容器的要求即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM