Jump to content
  • Advertisement
Sign in to follow this  
hothead

when should i use iterators?

This topic is 4998 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
you would use an iterator when you wanted to uhhh, iterate ? hehe, seriously though, yeah, you would use them to loop through something like a std::list or std::map and such.

EDIT: im not sure i really understood your question....

Share this post


Link to post
Share on other sites
You can also use iterators to store a location in the std::list, std::map, etc. Note tho that this is for temporary or short-length situations at best, since changing the contents or ordering of the container could change the value of the iterator

Share this post


Link to post
Share on other sites
That is a secksy avatar. Kingdom Hearts, right? I wish I still had a PS2 just for that game. But then...that costs money.

Anyway, iterators are used to loop through things. Read this question half an hour ago and I decided to just leave it alone, but I, too, want you to elaborate upon the quEstIOn thaT is aTa HANDA, so thata I can'a HELPA you witha your pro-ba-leMA!

[/rant]

Share this post


Link to post
Share on other sites
Use iterators for two three things:

1. Where you used to use an index variable when looping through an array.

2. Where you used to use an index variable or pointer to refer to a specific element in an array.

3. Wacky C++ iterator stuff like ostream_iterator.

Share this post


Link to post
Share on other sites
another place you would want to user iterators is when you want to use std:: algorithms... alot of them take iterators to operate on... same thing goes with member functions of std containers, things like .erase()

Share this post


Link to post
Share on other sites
Quote:
Original post by Boku San
That is a secksy avatar. Kingdom Hearts, right? I wish I still had a PS2 just for that game. But then...that costs money.

Anyway, iterators are used to loop through things. Read this question half an hour ago and I decided to just leave it alone, but I, too, want you to elaborate upon the quEstIOn thaT is aTa HANDA, so thata I can'a HELPA you witha your pro-ba-leMA!

[/rant]

its cloud from ff7 and thnks guys

Share this post


Link to post
Share on other sites
Iterators were created in C++ to simplify data retrival. I generally use them whenever I want to loop thru every element in a vector, queue, ect. That question is kind of like asking "when should I use a while loop" - it depends.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!