Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2002-10-14 08:09:29


Yitzhak Sapir <yitzhaks_at_[hidden]> writes:

> On Mon, 14 Oct 2002, [Windows-1252] Terje Slettebø wrote:
>
> > >From: "Yitzhak Sapir" <yitzhaks_at_[hidden]>
> >
> > >Anyway, now, if I write a bidirectional iterator,
> > >does a standard bidirectional iterator (ie, a bidirectional iterator as
> > >defined by the standard) me to provide such an implementation such that,
>
> That should have said "require me to provide an implementation such that"
>
> > >"if x == end(), and the sequence in question is non empty, --x provides a
> > >valid iterator to the element before the end"?
> >
> > That's how I understand it, yes.
> >
> > 23/9 says, "If the iterator type of a container belongs to the bidirectional
> > or random access iterator categories (24.1), the container is called
> > reversible and satisfies the additional requirements in Table 66:"
>
> I read that as a condition for an STL Container. Any STL container
> must meet this requirement. But my own UserDefinedContainer doesn't have
> to. Neither do iterator adaptors that are not related to containers.

<snip>

> Or does it mean that if I write an iterator and expect it to be a valid
> bidirectional/random access iterator, it must also be validly usable as a
> parameter to reverse iterator? If it does, do both the above conclusions
> hold? That I must write an end() such that -- is valid and safe for it,
> (if it compiles), and that it cannot hold a cached reference (if
> *reverse_iterator compiles?)
>
> Have I gone too far here?

This is really about iterators, not iterator adaptors or
containers. Keep your eye on the bouncing iterator. Look at Table 75
(Bidirectional Iterator Requirements) in the standard. The first line
tells you everything you need to know:

                          operational assertion/note
expression return type semantics pre/post-condition

--r X& pre: there exists s such
                                       that r == ++s.
                                       post: s is dereferenceable.
                                       --(++r) == r.
                                       --r == --s implies r == s.
                                       &r == &--r.

-- 
           David Abrahams * Boost Consulting
dave_at_[hidden] * http://www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk