input iterators and substitution property

S

subramanian100in

Suppose 'a' and 'b' are input iterators.

In the ISO/IEC 14882:2003 document, in section '24.1.1 Input
Iterators' in page 517, item 3 (below table 72) mentions the
following:
For input iterators 'a and 'b', 'a == b' does not imply '++a == ++b'.

I am unable to understand this sentence. Kindly give an example where,
for two input iterators 'a' and 'b', we have 'a == b' holds good but '+
+a' is not equal to '++b'. I am unable to come with an example to
understand this sentence in the standard document.

Kindly explain.

Thanks
V.Subramanian
 
R

red floyd

Suppose 'a' and 'b' are input iterators.

In the ISO/IEC 14882:2003 document, in section '24.1.1 Input
Iterators' in page 517, item 3 (below table 72) mentions the
following:
For input iterators 'a and 'b', 'a == b' does not imply '++a == ++b'.

I am unable to understand this sentence. Kindly give an example where,
for two input iterators 'a' and 'b', we have 'a == b' holds good but '+
+a' is not equal to '++b'. I am unable to come with an example to
understand this sentence in the standard document.

std::istream_iterator
 
Ö

Öö Tiib

Suppose 'a' and 'b' are input iterators.

In the ISO/IEC 14882:2003 document, in section '24.1.1 Input
Iterators' in page 517, item 3 (below table 72) mentions the
following:
For input iterators 'a and 'b', 'a == b' does not imply '++a == ++b'.

I am unable to understand this sentence.

First ... using operands with side effects for comparison operator is
ugly anyway.

When input iterators a == b then the a and b have same value. After
operator ++ is applied to one of them the other of them is no longer
required to be dereferenceable, and so ++ can not be applied to it and
so further == does not make any sense.
 
K

Kai-Uwe Bux

I request you to kindly give a code sample where a == b is true but +
+a is not equal to ++b.

Impossible. All one can give is an example, where equality is not
guaranteed. That is not the same as non-equality being guaranteed. Consider,
for example:

int main ( void ) {
std::istream_iterator< char > a ( std::cin );
std::istream_iterator< char > b ( a );
assert( a == b );
++ a;
++ b;
assert( a == b ); // not guaranteed
}

The second assert _may_ fail. There is, however, no guarantee that is does.


Best

Kai-Uwe Bux
 
J

James Kanze

Impossible. All one can give is an example, where equality is
not guaranteed. That is not the same as non-equality being
guaranteed. Consider, for example:
int main ( void ) {
std::istream_iterator< char > a ( std::cin );
std::istream_iterator< char > b ( a );
assert( a == b );
++ a;
++ b;
assert( a == b ); // not guaranteed
}
The second assert _may_ fail. There is, however, no guarantee
that is does.

IIUC, the ++ b may fail as well. As soon as you've incremented
one of the iterators, just about anything you do with the other
becomes undefined behavior, I think.

Presumably, some of the checking implementations verify this,
and abort the program in the ++b.
 

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
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top