Topic: Defect Report: relationship between iterator and reverse_iterator incorrectly stated


Author: "glancaster" <glancaster@ntlworld.com>
Date: Sun, 6 May 2001 11:50:46 GMT
Raw View
Garry Lancaster wrote:
> > 24.4.1/1 [lib.reverse.iterators] states:
> >
> >  "Bidirectional and random access iterators have corresponding reverse
> > iterator adaptors ... The fundamental relation between a reverse
iterator
> > and its corresponding iterator i is established by the identity:
> > &*(reverse_iterator(i)) == &*(i - 1)."
> >
> >  However, bidirectional iterators do not support operator- so, strictly
> > speaking, the identity does not work for them.

Valentin Bonnard:
> It does mathematically. It isn't valid C++, nor is it expected
> to be.

It's certainly not a complete C++ program, but it's a valid fragment, at
least for random access iterators (since only they actually define
operator-). For example, imagine std::vector had an extra member function,
check_reverse_iterator_relationship. It could be written like so (inside the
definition of the std::vector template):

bool check_reverse_iterator_relationship()
{
    iterator i = end();

    return &*(reverse_iterator(i)) == &*(i - 1);
}

Which bit do you think is not valid and why?

It doesn't look much like any maths I recognise. It definitely looks like
C++.

> > It could be rephrased to
> > something like:
> >
> >  &*(reverse_iterator(i)) == &*(--(iterator(i)))
> >
> >  Both bidirectional and random access iterators support operator--.
>
> No. This isn't valid C++ either, and makes less sens mathematically,
> because of the side effect.

> There is no defect.

Again, I don't understand the thinking behind your comments.

Regards

Garry Lancaster
Codemill Ltd
Visit our web site at http://www.codemill.net

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: jpotter@falcon.lhup.edu (John Potter)
Date: Mon, 7 May 2001 01:31:35 GMT
Raw View
On Sat,  5 May 2001 23:23:31 GMT, Valentin.Bonnard@free.fr (Valentin
Bonnard) wrote:

> "glancaster"  wrote:
>
> > 24.4.1/1 [lib.reverse.iterators] states:
> >
> >  "Bidirectional and random access iterators have corresponding reverse
> > iterator adaptors ... The fundamental relation between a reverse iterator
> > and its corresponding iterator i is established by the identity:
> > &*(reverse_iterator(i)) == &*(i - 1)."
> >
> >  However, bidirectional iterators do not support operator- so, strictly
> > speaking, the identity does not work for them.
>
> It does mathematically. It isn't valid C++, nor is it expected
> to be.

I agree, but it is unusual for the standard to require common sense of
the reader.

> There is no defect.

There is a precident in 25/9.  If that were moved to clause 17, it would
solve this problem and possibly some others.

John

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: "glancaster" <glancaster@ntlworld.com>
Date: Mon, 7 May 2001 10:47:55 GMT
Raw View
Garry Lancaster wrote:
> > > 24.4.1/1 [lib.reverse.iterators] states:
> > >
> > >  "Bidirectional and random access iterators have corresponding reverse
> > > iterator adaptors ... The fundamental relation between a reverse
> > > iterator
> > > and its corresponding iterator i is established by the identity:
> > > &*(reverse_iterator(i)) == &*(i - 1)."
> > >
> > >  However, bidirectional iterators do not support operator- so,
> > > strictly
> > > speaking, the identity does not work for them.
> >
Valentin Bonnard wrote:
> > It does mathematically. It isn't valid C++, nor is it expected
> > to be.
>
John Potter wrote:
> I agree, but it is unusual for the standard to require common sense of
> the reader.

See earlier reply for validity of fragment as C++.

All 3 of us understand what was meant by the paragraph, as far as is
possible
without actually being the ones that wrote it (you weren't, were you?).
My concern, like yours, is that it may mislead others. To say that anyone so
misled lacks common sense is too harsh. It could happen to anyone who
hadn't had a great deal of experience with iterator categories or who hadn't
read the whole of the iterator sections of the standard.

> > There is no defect.
>
> There is a precident in 25/9.  If that were moved to clause 17, it would
> solve this problem and possibly some others.

I agree this would solve the problem. If there are many similar problems, I
would prefer this solution, but I couldn't find any more, at least in clause
24. Please post 'em if you've got 'em.

The danger of a change with global effect is that people who only read
clause 24, for example, will miss it. Much as with variables in code, local
is usually better than global.

Regards

Garry Lancaster
Codemill Ltd
Visit our web site at http://www.codemill.net





---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: "glancaster" <glancaster@ntlworld.com>
Date: 05 May 01 14:55:24 GMT
Raw View
 [Moderator's note: this defect report has been
 forwarded to the C++ committee. -moderator(fjh).]

24.4.1/1 [lib.reverse.iterators] states:

 "Bidirectional and random access iterators have corresponding reverse
iterator adaptors ... The fundamental relation between a reverse iterator
and its corresponding iterator i is established by the identity:
&*(reverse_iterator(i)) == &*(i - 1)."

 However, bidirectional iterators do not support operator- so, strictly
speaking, the identity does not work for them. It could be rephrased to
something like:

 &*(reverse_iterator(i)) == &*(--(iterator(i)))

 Both bidirectional and random access iterators support operator--.

 Regards
 --
Garry Lancaster
Codemill Ltd
mailto: glancaster@*nospam*codemill.net
Visit our web site at http://www.codemill.net
---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]




Author: Valentin.Bonnard@free.fr (Valentin Bonnard)
Date: Sat, 5 May 2001 23:23:31 GMT
Raw View
"glancaster"  wrote:
>  [Moderator's note: this defect report has been
>  forwarded to the C++ committee. -moderator(fjh).]

I forward this post too.

> 24.4.1/1 [lib.reverse.iterators] states:
>
>  "Bidirectional and random access iterators have corresponding reverse
> iterator adaptors ... The fundamental relation between a reverse iterator
> and its corresponding iterator i is established by the identity:
> &*(reverse_iterator(i)) == &*(i - 1)."
>
>  However, bidirectional iterators do not support operator- so, strictly
> speaking, the identity does not work for them.

It does mathematically. It isn't valid C++, nor is it expected
to be.

> It could be rephrased to
> something like:
>
>  &*(reverse_iterator(i)) == &*(--(iterator(i)))
>
>  Both bidirectional and random access iterators support operator--.

No. This isn't valid C++ either, and makes less sens mathematically,
because of the side effect.

There is no defect.

  -- VB

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]