Topic: Relaxing the ++r == ++s requirement for forward iterators


Author: freyburg@gamut.stanford.edu (Brian Michael Freyburger)
Date: 1996/06/07
Raw View

In article <FREYBURG.96Jun6112611@gamut.stanford.edu>
  freyburg@Stanford.EDU (Brian Michael Freyburger) writes:
> Currently, forward iterators have the requirement that
>
> "r == s and r is dereferenceable implies ++r == ++s".
>
> It is explicitely stated in the draft to achieve the purpose of
> allowing multi-pass algorithms on forward iterators [see the note at
> 24.1.3.2].
>
> However, the slightly relaxed condition:
>
> "r is dereferenceable imples ++r == ++X(r)"
>
> still allows for multi-pass algorithms.  In fact, the
> only valid way to create a multi-pass algorithm is too copy the
> iterator, and pass through the data multiple times.

I since realized that this condition is not strong enough to allow
multi-pass algorithms.  It is only the "base case".  [It does not
require that ++(++r) == ++(++X(r)) when r and ++r are dereferenceable.]

Either of the following two definitions are complete however:

1) r is definitions imples ++r == ++X(r)
   r == s and ++r == ++s implies ++(++r) == ++(++s)

2) Define the relationship equiv(.,.) as follows:

   equiv(r, X(r))
   equiv(r, s) and r is dereferenceable implies equiv(++r, ++s)

   Now, the condition that must be maintained for forward iterators is
   "equiv(r, s) implies r == s".

   [Note that equiv used just for purposed of this definition, and not
    actually a C++ function.]

The first definition is easier to write, but still more restrictive
than the second (though the stride_iterator I posted before obeys both
definitions).

Brian Freyburger


[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]