theebugger
theebugger

Reputation: 87

How can I see the actual implementation code of different data structures in C++?

Is there a way to look at the actual code which is used to implement different data structures like list, vector<>, unorderd_map<>, map, set in C++.

I was willing to see just how efficient these implementations are.

And I am surprised that Google has no reasonable result on this.

Thanks.

Upvotes: 0

Views: 401

Answers (1)

Mysterious User
Mysterious User

Reputation: 308

There are different implementations of the C++ standard, and some of them are open-source. For example, gcc's implementation is called libstdc++. The source code for std::vector<T>, for example, can be consulted here: https://gcc.gnu.org/onlinedocs/gcc-4.6.3/libstdc++/api/a01115_source.html

An interesting example of what you you can see in the file is that std::vector<T>::push_back() simply calls std::vector<T>::emplace_back():

00370       template<typename _Up = _Tp>
00371         typename __gnu_cxx::__enable_if<!std::__are_same<_Up, bool>::__value,
00372                     void>::__type
00373         push_back(_Tp&& __x)
00374     { emplace_back(std::move(__x)); }

Upvotes: 2

Related Questions