input iterators and substitution property

Discussion in 'C++' started by subramanian100in@yahoo.com, India, May 10, 2010.

  1. , India

    , India Guest

    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
    , India, May 10, 2010
    #1
    1. Advertising

  2. , India

    red floyd Guest

    On May 10, 8:41 am, ", India"
    <> wrote:
    > 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
    red floyd, May 10, 2010
    #2
    1. Advertising

  3. , India

    , India Guest

    * red floyd <> wrote:
    > On May 10, 8:41 am, ", India"
    >
    > <> wrote:
    > > 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


    I request you to kindly give a code sample where a == b is true but +
    +a is not equal to ++b.
    , India, May 10, 2010
    #3
  4. , India

    Öö Tiib Guest

    On 10 mai, 18:41, ", India"
    <> wrote:
    > 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.
    Öö Tiib, May 10, 2010
    #4
  5. , India

    Kai-Uwe Bux Guest

    , India wrote:

    > * red floyd <> wrote:
    >> On May 10, 8:41 am, ", India"
    >>
    >> <> wrote:
    >> > 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

    >
    > 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
    Kai-Uwe Bux, May 10, 2010
    #5
  6. , India

    James Kanze Guest

    On May 10, 5:27 pm, Kai-Uwe Bux <> wrote:
    > , India wrote:
    > > * red floyd <> wrote:
    > >> On May 10, 8:41 am, ", India"


    > >> <> wrote:
    > >> > 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


    > > 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.


    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.

    --
    James Kanze
    James Kanze, May 11, 2010
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Azumanga

    Equality on input iterators

    Azumanga, Aug 13, 2004, in forum: C++
    Replies:
    2
    Views:
    632
    Andrew Koenig
    Aug 13, 2004
  2. Marcin Kaliciñski

    Iterators and reverse iterators

    Marcin Kaliciñski, May 8, 2005, in forum: C++
    Replies:
    1
    Views:
    475
    Kai-Uwe Bux
    May 8, 2005
  3. kevin  cline
    Replies:
    2
    Views:
    2,383
    Gilbert Rebhan
    Jul 26, 2008
  4. , India
    Replies:
    10
    Views:
    1,056
    James Kanze
    Aug 8, 2009
  5. Peng Yu
    Replies:
    7
    Views:
    103
    Jochen Lehmeier
    Jan 25, 2010
Loading...

Share This Page