c++ vector source code

后端 未结 4 2269
眼角桃花
眼角桃花 2021-02-20 10:44

I am trying to get the vector source code to see how the standard std or stl vector is implemented.

This is for learning purpose. Now the question is where can i find t

相关标签:
4条回答
  • 2021-02-20 11:18

    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.

    0 讨论(0)
  • 2021-02-20 11:28

    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.

    0 讨论(0)
  • 2021-02-20 11:31

    Here you are: http://www.sgi.com/tech/stl/download.html.

    0 讨论(0)
  • 2021-02-20 11:37

    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

    0 讨论(0)
提交回复
热议问题