style: for(nth_elem_in_list, end_of_list; next)

Discussion in 'C++' started by Gernot Frisch, Jul 28, 2004.

  1. 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
    Gernot Frisch, Jul 28, 2004
    #1
    1. Advertising

  2. On Wed, 28 Jul 2004 15:58:26 +0200, Gernot Frisch <> wrote:

    > 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
    John Harrison, Jul 28, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Deniz Bahar
    Replies:
    2
    Views:
    464
    Andrey Tarasevich
    Mar 9, 2005
  2. =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki

    Reading of file by next of map file and by next of file descriptor.

    =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki, Jul 10, 2007, in forum: C++
    Replies:
    1
    Views:
    787
    Alf P. Steinbach
    Jul 10, 2007
  3. Ken Varn
    Replies:
    0
    Views:
    443
    Ken Varn
    Apr 26, 2004
  4. Tad McClellan
    Replies:
    3
    Views:
    138
    Edward Wijaya
    May 13, 2004
  5. Liora
    Replies:
    5
    Views:
    635
    Tad McClellan
    Jan 12, 2007
Loading...

Share This Page