[gameprogrammer] Re: Iterator question/organize a vector
- From: "Alan Wolfe" <alan.wolfe@xxxxxxxxx>
- To: gameprogrammer@xxxxxxxxxxxxx
- Date: Mon, 3 Mar 2008 10:51:45 -0800
Yep, that is a lot clearer
maybe it'd be worth giving STL a try sometime :P
On 3/2/08, Matthew Weigel <unique@xxxxxxxxxxx> wrote:
> Alan Wolfe wrote:
> > I know some people think STL rules, but of the game programmers ive
> > talked to about it, nobody seems to really use it.
>
> Works great here :-) Most of the other game programmers I've spoken with in
> Austin seem to be happy with it, too. I know a fair number of people still
> working in C, but... well, they're just crazy.
>
> > IMO this is a case in point where STL isn't so hot; It's unclear the
> > right way to do a simple operation - something you could have coded
> > yourself in just a few minutes (:
>
> First of all, http://www.sgi.com/tech/stl/Vector.html is a great resource.
>
> Second of all... STL or no, that seems like a very complicated and inefficient
> way to swap two elements. Vectors provide *linear time insertion and removal*
> of elements in the middle of the array. Both the insert() and erase() calls
> are walking forward from where iter1 is, moving each element up and then down
> one element.
>
> Here's how I would do it, and I think even Alan will agree that it's a fairly
> clear and intuitive way of doing it:
>
> // using indices, which are neither faster nor slower than iterators,
> // but more clear in this case
> std::string temp = word[idx1];
> word[idx1] = word[idx2];
> word[idx2] = temp;
>
> And finally, to answer the question directly (using the SGI STL reference):
>
> A vector's iterators are invalidated when its memory is reallocated.
> Additionally, inserting or deleting an element in the middle of a
> vector invalidates all iterators that point to elements following
> the insertion or deletion point.
> --
> Matthew Weigel
> hacker
> unique & idempot.ent
>
> ---------------------
> To unsubscribe go to http://gameprogrammer.com/mailinglist.html
>
>
>
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- References:
- [gameprogrammer] Re: AI in games
- From: Robbert de Groot
- [gameprogrammer] Iterator question/organize a vector
- From: David Olsen
- [gameprogrammer] Re: Iterator question/organize a vector
- From: Chris Nystrom
- [gameprogrammer] Re: Iterator question/organize a vector
- From: Alan Wolfe
- [gameprogrammer] Re: Iterator question/organize a vector
- From: Matthew Weigel
Other related posts:
- » [gameprogrammer] Iterator question/organize a vector
- » [gameprogrammer] Re: Iterator question/organize a vector
- » [gameprogrammer] Re: Iterator question/organize a vector
- » [gameprogrammer] Re: Iterator question/organize a vector
- » [gameprogrammer] Re: Iterator question/organize a vector
- » [gameprogrammer] Re: Iterator question/organize a vector
- » [gameprogrammer] Re: Iterator question/organize a vector
- » [gameprogrammer] Re: Iterator question/organize a vector
- [gameprogrammer] Re: AI in games
- From: Robbert de Groot
- [gameprogrammer] Iterator question/organize a vector
- From: David Olsen
- [gameprogrammer] Re: Iterator question/organize a vector
- From: Chris Nystrom
- [gameprogrammer] Re: Iterator question/organize a vector
- From: Alan Wolfe
- [gameprogrammer] Re: Iterator question/organize a vector
- From: Matthew Weigel