Back To Basics: C++ Containers

Containers provided by the standard library in C++ have almost become as essential as the language keywords themselves. Storing data in the correct way will make you a fluid and stronger programmer, as you can let the containers do the hard work for you. In this video I take a really brief look at the main containers std::array, std::vector, std::list, std::deque, std::set, std::unordered_set, std::map, std::unordered_map.



46 thoughts on “Back To Basics: C++ Containers

  1. If a method is already declared, you shouldn't need to reintroduce it as a new method. Then you're just entrapping yourself in a bottomless cycle.

  2. I program in C and hate C++ because it's so complex and has tons of features to learn, but I think after watching this video that it is actually possible. Great explanation and thanks

  3. Is there any limit to the dimensions of containers you could link them up such that you could accelerate tables of results by cycling through the powers of number to read the pre generated results from within the link list at higher powers could resolve questions rather than computing the results on demand. Could they work back wards such as when your applying bitmap image onto a 3d object. ;%::$?

  4. If you set up your for loop to use x < array.size(), is it checking size() every pass or does the compiler just check it once and use that value every time it loops through?

  5. Mr. Beautiful beard man strikes my heart again>
    You are in my opinion one of the best, if not the best, people out there for content to watch. Thank you so much for what you have done for the community

  6. I was trying to enter your code for the "vector" example. I'm getting errors, though. Do you have a list of the running code? Also, does it run on the g++ compiler?

  7. this video is a godsend! i am self taught, so there is some knowledge gaps, prior to this i have mainly paid attention to time complexity, but the way you explain the memory allocation for each container is so good in this! learned a ton from it

  8. Thank you for uploading this; it's a really useful resource on my own learning journey! I started C++ from scratch on a part-time basis in Sept 2020, and have basically been beasting arrays (of the 1D and multi-dimensional variety), loops, basic recursion, and some very simple classes/structs since. It was a linear learning process, including working out the 'easier' problem solving exercises. However, the next step up demands more…I dipped my toe in the murky waters of STL, and had it bitten off by some of the coding problems that demand their usage; so it's great to see the containers explained in a manner that sticks ice-cubes down the back of the learning fatigue that had set in. Your channel does for complicated programming concepts what something like 'Grokking Algorithms' did very for the far more elementary.

  9. I appreciate that JAVID9X doesn’t like to “patronize” those who learn from him and appreciate how he empowers the coder to think about how the program runs for him or herself.

    With that being said… these “Back to basic” videos… especially the pointers tutorial and this containers tutorial… are extremely helpful in understanding even the most basic games on OLC if you are not a C++ wizard. I would highly recommend anyone reading this comment to go watch how the Tetris game is made and how the Tetris blocks are indexed. It makes even some of the most sophisticated games on OLC make sense to me. Anyways hope this helps someone cause I was really frustrated at first trying to learn this stuff, thank you so much javid9x

  10. 11:01 As a physicist i would say that a vector is an arrow. The general usage as some point is absolutely confusing and doesn't make much sense. Of course, an arrow can point on some point, but in general it points to the direction of some point.

  11. As someone old enough to know how studying programming or just about any other science subjects looks like without youtube or udemy, I never forget to say that videos like this one and creators like you are a treasure.
    Even though I had successfully defended a cpp project for my engineering thesis, I have still remained at a cpp amateur/intermediate level, because of my laziness and lack of consistency in learning.
    I appreciate series like "Back To Basics" a lot. Thank you for providing high quality, in-depth lessons for us for free.

  12. Hey, may I ask, are there going to be more Lua C++ tutorials? I have recently started to implement lua into my game engine and am interested in more Lua videos!

  13. hmm, although i dont know enough about c++ to say much, the whole randomly jumping and copying the entire array was a big turnoff for me, like that is so much waste that can be avoided if someone plans well for memory allocation and what not right? The timing differences, even if we're talking about microseconds, still showed quite a large difference for when the memory space is contiguous vs not :

  14. Great educational content. I'm not a programmer and I've only used languages like python or R, in which you usually don't think about memory allocation. Anyways. I was wondering: why the "basic" array structure in c++ even exist? In other words, why it isn't made so that it behaves like the std::array by default?

  15. Noob question: why would you want to use an std::vector as an std::array if you already have the possibility to create an std::array of a known allocated size? Is if because you can create a vector that allocates the space but can then add elements dynamically to it?

  16. I think Benchmarking your specific usecase should have been mentioned here. Yes some containers might be faster in theory, but in practice, using a vector will be the most practical and even the fastest since cpu caching loves contiguous memory. That is often regardless of how often you resize the vector.

  17. Javid, great video as always. Your university teaching material man!
    Couple of questions:
    1) How is the original memory size determined for vectors, deques, etc? How does it now with how many space contiguous allocations to start?
    2) the size of the block for the deque seemed to be increasing. Is that so?
    3) is it possible to have graph like structures with vectors? (ie non-single node connections)

  18. Nice…
    Can you touch on how do you know how to use a header / api file?

    Such as including <iostream>?
    You open the .h file and see the prototype function with a description on how to use?

    Really can not use any libraries or exploring / contributing to open source projects (such as Blender) without just messing around with the source code….

Leave a Reply

Your email address will not be published. Required fields are marked *