Re: list and iterators

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jeff F (not_at_anywhere.com)
Date: 06/06/04

  • Next message: Ele: "fixed size of data types on Windows"
    Date: Sun, 6 Jun 2004 15:41:13 -0400
    
    

    "Nelson" <doomer999@hotmail.com> wrote in message
    news:%23Nk%23N09SEHA.544@TK2MSFTNGP11.phx.gbl...
    > Hi,
    >
    > I tried to cast a reverse_iterator of list to an iterator, but it does not
    > work.
    > It's strange that an iterator can be cast to a reverse_iterator without
    > problem.

    You don't cast them. You call the base() method to get (ahem) the base
    iterator that reverse_iterator adapts.

        typedef std::list<MyType> tList;

        tList MyList;

        tList::reverse_iterator lRItr = MyList.rbegin();
        tList::iterator lItr = lRItr.base();

        assert( lItr == MyList.end() );

    >
    > Why is it so? Aren't iterators just pointers?

    Nope.

    Jeff F


  • Next message: Ele: "fixed size of data types on Windows"

    Relevant Pages

    • Re: Foreach and Iterators
      ... for (Object orow: new MyIter()) { ... you'll need to change this Iterator to match. ... The error compiler complains about is: ... Of course, with the code that *does* work, the cast from Object to ...
      (comp.lang.java.help)
    • Re: Foreach and Iterators
      ... for (Object orow: new MyIter()) { ... public Iterator iterator() { ... my question is: why won't the following line compile: ... Of course, with the code that *does* work, the cast from Object to ...
      (comp.lang.java.help)
    • list and iterators
      ... I tried to cast a reverse_iterator of list to an iterator, ... It's strange that an iterator can be cast to a reverse_iterator without ... Aren't iterators just pointers? ...
      (microsoft.public.vc.language)
    • Re: list and iterators
      ... > You don't cast them. ... You call the basemethod to get (ahem) the base ... > iterator that reverse_iterator adapts. ... > Jeff F ...
      (microsoft.public.vc.language)
    • Re: New For Loop Syntax (for each)
      ... Matthew Jones wrote: ... > parameterized types are ready." ... cast the iterator variable into whatever type you need. ...
      (borland.public.delphi.non-technical)