Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > map::erase(reverse_iterator) is not allowed???

Reply
Thread Tools

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

 
 
noone@all.com
Guest
Posts: n/a
 
      03-14-2007
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.


 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      03-14-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) 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


 
Reply With Quote
 
 
 
 
noone@all.com
Guest
Posts: n/a
 
      03-14-2007

> 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


 
Reply With Quote
 
Marcus Kwok
Guest
Posts: n/a
 
      03-14-2007
(E-Mail Removed) 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
To be not, or not to be not? Ruby Freak Ruby 2 09-23-2008 08:04 AM
Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'? Kristian Domke Python 11 01-23-2008 07:27 PM
'' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long. rote ASP .Net 2 01-23-2008 03:07 PM
Cisco 3640 3620 3600 not detecting, not enabling, not working: NM-2FE2W Taki Soho Cisco 0 09-22-2004 07:28 AM
maintaining control with cookies (not strictly an ASP or even server side question. But not not either) Stephanie Stowe ASP General 2 04-07-2004 04:23 PM



Advertisments