Thread: size_t help

  1. #16
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    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,895
    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,149
    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,005
    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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > 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.

Popular pages Recent additions subscribe to a feed