[Dcmlib] Reverse Iterators vs std::sort
Jean-Pierre Roux
jpr at creatis.insa-lyon.fr
Tue Aug 30 11:49:15 CEST 2005
Hi !
Reverse iterators are well known (?) and work perfectly :
------------------------------------------------------------------
Reverse iterators are bidirectional iterators that invert the meaning of
operators +, -, ++ and --. Thus, incrementing a reverse iterator moves
it one position /backwards/, whereas decrementing it causes it to move
to the /next/ element. The rbegin() and rend() member functions return
reverse iterators:
void print_backwards(vector<int> &vi)
{
vector<int>::reverse_iterator rit=vi.rbegin();
while (rit<vi.rend())
{
cout<<*rit<<endl;
++rit; //move one position backwards
}
}
-----------------------------------------------
==> My question :
How can we use them (or anything else) to *reverse* std::sort a
std::vector (or any std::sortable object) ?
What I wouldn't like to write is something like the following stuff :
if (DirectOrder)
std::sort(fileList->begin(), fileList->end(),
userSuppliedLessThanFunction);
else
std::sort(fileList->begin(), fileList->end(),
userSuppliedGreaterThanFunction);
Thx
JPRx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.creatis.insa-lyon.fr/pipermail/dcmlib/attachments/20050830/a1860a40/attachment.html>
More information about the Dcmlib
mailing list