style: for(nth_elem_in_list, end_of_list; next)

G

Gernot Frisch

Hi,

I'm not very familiar with the std container classes, yet. What's your
favourite style of writing:

std::list<int> li;
std::list<int>::iterator it = li.begin();
std::advance(it, 5);
for( ; it!=li.end(); it++)
...


--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}

________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com
 
J

John Harrison

Hi,

I'm not very familiar with the std container classes, yet. What's your
favourite style of writing:

std::list<int> li;
std::list<int>::iterator it = li.begin();
std::advance(it, 5);
for( ; it!=li.end(); it++)
...

The only comment I'd make is to prefer ++it to it++. it++ has to do more
work than ++it (because it must save and return the old value of the
iterator as well as incrementing the iterator), so ++it may be more
efficient and is just a easy to type and understand.

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

std::list - access at index? 3
boost 2
int(a) vs (int)a 19
reference to parent inherritance? 9
unreachable code? 4
reference to array? 13
ifstream - nocreate - how to? 1
std::container - preallocation size? 5

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top