By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,412 Members | 1,007 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,412 IT Pros & Developers. It's quick & easy.

map::erase(reverse_iterator) is not allowed???

P: n/a
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;
}

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.

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.
Mar 14 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
no***@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
Mar 14 '07 #2

P: n/a
You're using "map" and "queue" interchangeably here. Are you aware
that 'queue' is a container adapter? Is your "queue" in fact a map?
Correct...the internals are a map based on my need for sort order
controlled extraction and deletion, but random insertion, and
quick searches...perhaps queue isn't the best term for the structure.
>
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());
Yup...I did something like

i--; // reverse iterator;
q.erase(q.begin(), i.base());

and at least it compiles now. I think I need to insert some range
checking though to cover the .end() method possibility when dealing with
iterator ranges
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...
you're probably right but the reverse_iterator more closely follows my
thinking since I'm more interested in reverse sort order. I suppose I
could have redefined the sort order for the container and used all forward
iterators but I didn't think of that until just now.

-Prowel
Mar 14 '07 #3

P: n/a
no***@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;
}

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 is correct; you need a regular iterator for erase().

This article (specifically Guideline 3) helps explain the relationship
between iterators and reverse_iterators and when you can just use the
base() function and when you must adjust it to get what you want:

http://www.ddj.com/dept/cpp/184401406

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Mar 14 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.