Re: map::erase(reverse_iterator) is not allowed???
noone@all.com wrote:
string operator()(const bool clean=true) {
string rv;
MPEGQUEUE::reverse_iterator i=thequeue.rbegin();
MPEGQUEUE::reverse_iterator t=thequeue.rend();
while (i!=thequeue.rend()) {
if (i->second->isComplete()) {
t=i;
i--;
if (clean)
for (MPEGQUEUE::reverse_iterator j=i;
j!=thequeue.rend(); ) {
delete j->second;
thequeue.erase(j++);
}
} else {
i--;
}
}
return rv;
My OE screws up formatting when tab chars are involved, sorry about
that.
}
thequeue.erase(j++) says "no matching function call". Is this
because the iterator is a reverse_iterator? Am I not allowed to
delete map entries based on a reverse_iterator? That would be an
ugly deficiency in the
STL since I need to delete all keyed entries (less than) the last
complete entry in the queue.
You're using "map" and "queue" interchangeably here. Are you aware
that 'queue' is a container adapter? Is your "queue" in fact a map?
There is no requirement that _any_ standard container supported
erasure from itself using a reverse_iterator. You can always get
the real iterator from the reverse iterator and pass that:
thequeue.erase((j++).base());
The application essentially reassembles network fragmented MPEG4
packets that may arrive out of order, at indeterminant times, or not
at all. the packets are timestamped, and only the most recent
(complete) frame is valid. Everything in the queue earlier than it
should be deleted upon complete reassembly of a newer frame. I also
still have to loop through the container to delete remove frames and
frame segments that have outlived their time to live value. Again, a
reverse iterator would be preferable.
For some reason methinks that any algorithm you can write in terms of
reverse iterators should be possible to rewrite in terms of normal
iterators. Although I could be wrong...
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask