Equality on input iterators

A

Azumanga

Hello.

A small question with regards input iterators.

Table 72 of the standard says with regards ++r on an input iterator r:

"any copies of the previous value of r are no longer required to be
dereferencable or in the domain of =="

Consider therefore the following code segment, where r is a currently
valid dereferencable input iterator.

a=r;
++r;

if(a==a) {} // Line 1
if(a==r) {} // Line 2
++a; // Line 3
a=r; // Line 4
I assume therefore lines 1,2 and 3 are undefined and anything could
happen (including a crash).
Line 4 is defined (although to be honest fairly pointless)

Is this a correct reading?

Thank you

Azumanga
 
V

Victor Bazarov

Azumanga said:
A small question with regards input iterators.

Table 72 of the standard says with regards ++r on an input iterator r:

"any copies of the previous value of r are no longer required to be
dereferencable or in the domain of =="

Consider therefore the following code segment, where r is a currently
valid dereferencable input iterator.

a=r;
++r;

if(a==a) {} // Line 1
if(a==r) {} // Line 2
++a; // Line 3
a=r; // Line 4
I assume therefore lines 1,2 and 3 are undefined and anything could
happen (including a crash).
Line 4 is defined (although to be honest fairly pointless)

Is this a correct reading?

I can't really vouch for its "correctness", I can only say that I read it
the same way. You could ask for clarification from the Committee members
in comp.std.c++ or comp.lang.c++.moderated.

Victor
 
A

Andrew Koenig

Consider therefore the following code segment, where r is a currently
valid dereferencable input iterator.

a=r;
++r;

if(a==a) {} // Line 1
if(a==r) {} // Line 2
++a; // Line 3
a=r; // Line 4
I assume therefore lines 1,2 and 3 are undefined and anything could
happen (including a crash).
Line 4 is defined (although to be honest fairly pointless)

Is this a correct reading?

Yes.

Input iterators are very, very limited. If you want to be able to do #1-3
above, you need at least a forward iterator.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top