Video Introduction to the STL, Part 1

Video Introduction to the STL, Part 1

  • Comments 6

I recently recorded the first part of a video lecture series introducing the Standard Template Library.  It assumes familiarity with C++, but begins with the STL basically from scratch.  Channel 9 hooked up my laptop so I could write, compile, and execute code as I went along.  Check it out here:

I'll be recording more parts of this series with Channel 9 in the near future, responding to your comments along the way.

Stephan T. Lavavej
Visual C++ Libraries Developer

Leave a Comment
  • Please add 7 and 1 and type the answer here:
  • Post
  • Very nice introduction to STL for beginners. Due to my laziness, I prefer to watch such informative tutorials to long books which make me fall asleep. I'm eagerly waiting for next parts, where you will go into detail about STL and various tricks/ideas linked to it.

    P.S. Why didn't you want to present "ranged-based for"? I thought it was in standard.

  • Visual C + + 2010 haven't implemented "range-base for" syntax.

    Even if it present the one that it is not possible to use it, it is meaningless.

    But, very similar "for each" have.

  • Thanks for this very nice introduction to STL.

    I've been writing some C code where I needed a dynamic array which I coded something like:

    struct list {

         int nument; // occupied entries

         int maxent; // total entries

         struct entry e[1]; // grows dynamically


    where struct entry is some unit data element I need to keep. This list is grown at demand and all the vector operations are provided. This looks exactly like the STL vector.

    Here's the catch, this implementation is used on a message passing system (like Erlang) where multiple (distributed) threads/processes communicated to pass on these lists. The message send function looks something like.

    msg_send(dest, start_address, size);

    As this is a C implementation I can directly get the start address and calculate the total size of my list. Also I can only include size consumed by used entries, so my message will not contain the whole list with empty entries.

    size = offsetof(list, e[nument]);

    The point is I *know* the memory layout of the whole thing.

    How to do this using STL vector?

    Is there any cleaner way to pass around contiguous STL containers, when I'm not *supposed to* look inside them?


  • [kudryavka]

    > Visual C + + 2010 haven't implemented "range-base for" syntax.

    In fact, I'm not aware of any compiler that has implemented the range-based for-loop yet. It is very new.

    > But, very similar "for each" have.

    Please don't use the non-Standard "for each" extension. It has nasty gotchas.


    > I've been writing some C code

    Why are you writing C? Except in kernel mode, C++ supersedes C.

    > How to do this using STL vector?

    vector is guaranteed to be contiguous.

    C++98/03 (VC9): When v is non-empty (that is, if !v.empty()), you can say &v[0] to get a pointer to the vector's elements (there are v.size() elements). You can pass this pointer to C functions, and if the vector is modifiable, the C functions can modify the elements. When v is empty, you CANNOT say &v[0]. If you want to pass a null pointer for empty vectors, you'll need to say "v.empty() ? NULL : &v[0]".

    C++0x (VC10): Additionally, you can say to get a pointer to the vector's elements. This works even when v is empty (in that case, you'll get a pointer with an unspecified value, because [anything, anything) is a valid empty range. Specifically, it may not be null, and our maximally efficient implementation will return non-null pointers for empty vectors in many cases).

    Stephan T. Lavavej, Visual C++ Libraries Developer

  • Stephan, thank you so much for doing this video, and I would LOVE to see more of them in the future. You do a really great job of explaining these issues. I'm an experienced C++ developer, and I still learned a couple things from your video.

    Very nicely done indeed.  :-)

  • I'm glad you liked it! Part 2 was posted today:

    Stephan T. Lavavej, Visual C++ Libraries Developer

Page 1 of 1 (6 items)