[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: Trouble with iterators QStringList
From:       Richard Smith <kde () metafoo ! co ! uk>
Date:       2004-07-28 19:36:25
Message-ID: 200407282036.25342.kde () metafoo ! co ! uk
[Download RAW message or body]

On Wednesday 28 July 2004 8:11 pm, heiko.evermann@gmx.de wrote:
> What is the correct way to iterate backwards?

If QStringList were an STL container, you'd use rbegin() and rend() instead of 
begin() and end(), then iterate forward with it++ as usual. Unfortunately, it 
doesn't support reverse iterators. However, its iterators are bidirectional, 
so it doesn't need to, since the STL provides a iterator->reverse iterator 
adapter, reverse_iterator.

Here's your answer then:

#include <iterator>

typedef std::reverse_iterator<QStringList::iterator> 
QStringListReverseIterator;
QStringListReverseIterator rbegin( list.end() ), rend( list.begin() );

for( QStringListReverseIterator it = rbegin; it != rend; ++it )
	whatever;

Hope that helps,
Richard
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic