size_t help

This is a discussion on size_t help within the C++ Programming forums, part of the General Programming Boards category; Sure, but that's not as clear....

  1. #16
    Registered User
    Join Date
    Apr 2006
    Posts
    2,009
    Sure, but that's not as clear.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  2. #17
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    I never had problems iterating in reverse
    Code:
    template <typename BidiRange>
    void foo(BidiRange &rr)
    {
      for(typename range_reverse_iterator<BidiRange>::type ri = rbegin(rr), re = rend(rr); ri != re; ++ri) {
        // Whatever.
      }
    }
    Last edited by CornedBee; 11-02-2007 at 03:41 PM.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #18
    Registered User
    Join Date
    Apr 2006
    Posts
    2,009
    Sure, but that requires the use of iterators. Sometimes subscripting is more convenient. Unless you're making the argument that subscripting should never be used to iterate through each value an array -- forwards or backwards.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  4. #19
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    My rule of thumb for unsigned values being reverse iterated is to use a do...while.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #20
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,333
    > But that creates a pointer value which is undefined, according to the standard.
    Yes, just as "undefined" as your negative subscript - what's your point?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21