At 2:06 PM -0700 6/14/04, Dave Whipp wrote:
"Dan Sugalski" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
 >Why not take a page from C++ and call "previous" and "next" C<inc> and
 >C<dec>, and then C<deref> to get what it points to.

 Because ++ and -- affect the value not the container. (There are days
 when I think "C++ does it like..." is the near-perfect argument
 against doing it one particular way... :) Next and previous are
 actions on the container.

Whatever you name the next/previous operations, you need a way to distinguish operations on the container from operations on the containee -- i.e. the C<deref> operator. Otherwise how would you iterate over a list of iterators?

Erm... you iterate over the list, and as it returns its contents you iterate over that?


Personally, I like the flexibility of the C++ approach (though some of its
limitations will hopefully be fixed in a future iteration of the standard).
Being able to add/subtract values other than 'one' to/from an iterator can
be useful, especially when iterating over an array. Then C<reset> can be
implemented by subtracting the current C<pos>; and C<last> is implemented by
adding "size-pos" (modulo an out-by-one error).

These are just methods. (I don't believe I just said that...) We can always enhance the protocol later.


Incidentally, the ability to implement C<reset> implies that an iterator has
some way of finding its parent container.

Hell, the ability of iterators to iterate implies that the iterator has a hold on its parent container. This is just fine with me. (And it makes sense as the normal way to iterate over a container--it's the way that springs to mind first, at least for me)
--
Dan


--------------------------------------it's like this-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                      teddy bears get drunk

Reply via email to