Dissecting the C++ STL Vector: Part 4 – Insertion

Part 4 of the series will cover one of the two most important features of the vector container, namely insertion. The next part will cover deletion, which will be last part about the source code. Future parts will cover the theory behind the vector container. We will be interested in only the insert method group. Continue reading

Dissecting the C++ STL Vector: Part 3 – Capacity & Size

This is the third part of a series about dissecting the vector container in C++. It depends on the first part and the second part, so make sure that you have read them before continuing. In this part, I will dissect the “capacity” methods of the vector template. That is, size, max_size, resize, capacity, empty, reserve, and shrink_to_fit. It will be relatively simpler than the previous parts. In fact, as you will see, the implementation of most of these methods is obvious. My goal is to help you be more familiar with the vector template before I start discussing the most important methods, namely insert and erase. Continue reading

Dissecting the C++ STL Vector: Part 2 – Constructors

This is the second part of a series about dissecting the vector container in C++. It depends on the first part, so make sure that you have read it before continuing. In this part, I will dissect the constructors of the vector container. You will learn about all the fields of a vector instance, what do they represent, and how they are being initialized. You will be able to compute the size of any vector instance. Also you will see how allocators are involved into construction and the exceptions that might occur along the way.   Continue reading

Dissecting the C++ STL Vector: Part 1 – Introduction

This is the beginning of a series about the vector container of the C++ Standard Template Library. While there are numerous resources discussing how and when to use this container, this series will be a little bit more advanced. We will get our hands dirty by ruthlessly dissecting the vector container source code. People usually (or never) talk about the source code mainly because there is no need to know anything about it. However, I always like to see what’s happening behind the scenes and so I’ve started this series. It will be hard because the source code is not well-documented and I haven’t seen any articles going at this depth. I will do my best to present the information as accurately as possible. The beginning will be about the programmatic aspects of the vector template and then I will slowly move towards the theory behind it. This part will introduce you to the vector template source code. Continue reading