Jump to content


STL Collection Reference


9 replies to this topic

#1 eddie

    Senior Member

  • Members
  • PipPipPipPip
  • 751 posts

Posted 05 January 2006 - 12:22 AM

Hey!

I made a blog post about this, but I figure some people on DevMaster might be interested on this as well.

The summary: I'm trying to compound a list of Features/Constraints of the STL container classes, for easy reference when you're deciding which to use in your programming (side note: I remember seeing a flow chart somewhere on the web that described this. Anyone seen it?).

This is mostly for my benefit as I've never been formally introduced to STL, I just sort of "picked it up". I hope it helps someone else.

Here's the blog post, the document can be found from a link inside it:

http://www.kickingdr.../stl-reference/

#2 .oisyn

    DevMaster Staff

  • Moderators
  • 1822 posts

Posted 05 January 2006 - 10:54 AM

First remark: std::vector: "insert/delete will invalidate iterators"
When you delete, it will only invalidate the iterators starting from the one you delete, all the iterators that point to an element before the one being deleted remain intact. Same goes for insert when the current capacity is large enough to hold the inserted items :)
C++ addict
-
Currently working on: the 3D engine for Tomb Raider.

#3 eddie

    Senior Member

  • Members
  • PipPipPipPip
  • 751 posts

Posted 05 January 2006 - 11:24 AM

Right, that makes sense.

Fixed. :)

Thanks for the feedback. The page is pretty basic now, but I'd like it to grow into a general cheat sheet for people unfamiliar with STL Collections, and well, me, when I'm feeling stupid. :)

#4 monjardin

    Senior Member

  • Members
  • PipPipPipPip
  • 1033 posts

Posted 05 January 2006 - 12:27 PM

I have a really good cheat sheet that describes all the containers and algorithms. It's on my desk at work. I'll dig up a link when I get to the office and send it to you.

#5 eddie

    Senior Member

  • Members
  • PipPipPipPip
  • 751 posts

Posted 05 January 2006 - 12:31 PM

That'd be handy, thanks! Even if I just link to it.

I'm basically looking for one-stop shopping. :)

#6 monjardin

    Senior Member

  • Members
  • PipPipPipPip
  • 1033 posts

Posted 05 January 2006 - 02:07 PM

You can download it here: http://www.medini.or...lqr-1.27.tar.gz or here: http://www.medini.or...ad/stlqr127.zip. Its a postscript file that prints nicely in landscape on the front and back of 4 pages.
It's a quick reference, from a fellow named Yotam Medini, with the syntax of all the containers and algorithms. It's not helpful for tid-bits like when iterators are invalidated. However, I would forget a lot of those algorithms existed if I didn't have this thing handy. ;)

#7 geon

    Senior Member

  • Members
  • PipPipPipPip
  • 893 posts

Posted 06 January 2006 - 12:05 PM

Have a look at the original SGI reference:

http://www.sgi.com/t...f_contents.html

Great stuff.

#8 eddie

    Senior Member

  • Members
  • PipPipPipPip
  • 751 posts

Posted 06 January 2006 - 12:25 PM

Yup. I've got those actually as links in my document.

My point was to be a little more of a quick reference, than to compete with the completeness of the other doc.

#9 monjardin

    Senior Member

  • Members
  • PipPipPipPip
  • 1033 posts

Posted 06 January 2006 - 01:52 PM

Now that I think of it, the MSDN has some pretty good summary information. Here is an excerpt from the deque container description about when iterators are invalidated:

Quote

Deque reallocation occurs when a member function must insert or erase elements of the sequence:
  • If an element is inserted into an empty sequence, or if an element is erased to leave an empty sequence, then iterators earlier returned by begin and end become invalid.
  • If an element is inserted at the first position of the deque, then all iterators, but no references, that designate existing elements become invalid.
  • If an element is inserted at the end of the deque, then end and all iterators, but no references, that designate existing elements become invalid.
  • If an element is erased at the front of the deque, only that iterator and references to the erased element become invalid.
  • If the last element is erased from the end of the deque, only that iterator to the final element and references to the erased element become invalid.
Otherwise, inserting or erasing an element invalidates all iterators and references.
That seems pretty concise. Now, navigating to the right page without the help of Google is another issue... ;)

#10 eddie

    Senior Member

  • Members
  • PipPipPipPip
  • 751 posts

Posted 06 January 2006 - 07:44 PM

Yeah, that's exactly it.

Some pages have great information, but it's a pain to get to (I loathe starting up my MSDN documentation on my machine, it seems to have gotten *slower* with 2005), or finding everything concisely.

I'll hope to pool that information together, and massage it so it's useful. Then again, who knows, it might turn out so bloated I'll have to abandon it anyways.

<sigh> Documentation! Sheesh! :D





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users