473,406 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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

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
3 7411
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Pieter Thysebaert | last post by:
Hello, I've got a question conerning erasing key-value pairs from a std::map while iterating over it. According to the STL docs, erasing an element in a map invalidates all iterators pointing...
3
by: Tony Young | last post by:
Hi, I have a multimap container. I want to eliminate all "duplicate" elements. By duplicate I mean something like (3, 4), (4, 3) and (4, 3), in which I want to eliminate any two of these...
10
by: bolnvhuis | last post by:
I'm using an STL map in my code. My application sometimes tries to delete things twice from the map. This leads to a crash in my current code. The problem is probably the way I check whether it is...
2
by: rockkyy | last post by:
Hi all, ok here it goes.. I am going to implement a STL MAP.. say 'mapToken'..this is a GLOBAL map. This mapToken has many nodes with its keys ranging from t1,t2,t3 ....t100 . Now in...
4
by: sks | last post by:
I have a question regarding std::multimap/iterators. At the SGI website, it says "Erasing an element from a multimap also does not invalidate any iterators, except, of course, for iterators that...
6
by: Xernoth | last post by:
Hi, I have an exercise that requests the following: Write a function that reads words from an input stream and stores them in a vector. Use that function both to write programs that count the...
75
by: ume$h | last post by:
/* I wrote the following program to calculate no. of 'a' in the file c:/1.txt but it fails to give appropriate result. What is wrong with it? */ #include"stdio.h" int main(void) { FILE *f;...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.