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 the source code. Even source code of other C++ Container also helpful.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With