By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,300 Members | 1,369 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,300 IT Pros & Developers. It's quick & easy.

Equality on input iterators

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Azumanga wrote:
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
Jul 22 '05 #2

P: n/a
> 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.
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.