473,795 Members | 3,231 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

map::erase(reve rse_iterator) is not allowed???

string operator()(cons t bool clean=true) {
string rv;
MPEGQUEUE::reve rse_iterator i=thequeue.rbeg in();
MPEGQUEUE::reve rse_iterator t=thequeue.rend ();
while (i!=thequeue.re nd()) {

if (i->second->isComplete() ) {
t=i;
i--;
if (clean)
for (MPEGQUEUE::rev erse_iterator j=i;
j!=thequeue.ren d(); ) {
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_iterato r? Am I not allowed to delete map entries
based on a reverse_iterato r? 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 7468
no***@all.com wrote:
string operator()(cons t bool clean=true) {
string rv;
MPEGQUEUE::reve rse_iterator i=thequeue.rbeg in();
MPEGQUEUE::reve rse_iterator t=thequeue.rend ();
while (i!=thequeue.re nd()) {

if (i->second->isComplete() ) {
t=i;
i--;
if (clean)
for (MPEGQUEUE::rev erse_iterator j=i;
j!=thequeue.ren d(); ) {
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_iterato r? Am I not allowed to
delete map entries based on a reverse_iterato r? 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_iterato r. 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...perh aps queue isn't the best term for the structure.
>
There is no requirement that _any_ standard container supported
erasure from itself using a reverse_iterato r. 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_iterato r 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()(cons t bool clean=true) {
string rv;
MPEGQUEUE::reve rse_iterator i=thequeue.rbeg in();
MPEGQUEUE::reve rse_iterator t=thequeue.rend ();
while (i!=thequeue.re nd()) {

if (i->second->isComplete() ) {
t=i;
i--;
if (clean)
for (MPEGQUEUE::rev erse_iterator j=i;
j!=thequeue.ren d(); ) {
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_iterato r? Am I not allowed to delete map entries
based on a reverse_iterato r?
That is correct; you need a regular iterator for erase().

This article (specifically Guideline 3) helps explain the relationship
between iterators and reverse_iterato rs 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
5407
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 to that element so
3
3159
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 three. The most straightforward way I can think of is to first swap every member such that every member has its key smaller than its value. Then loop thru the multipmap and erase duplicates (please see the loop below). Is there a more automatic way...
10
2144
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 necessary to delete something (line 44 and 52 in below code). In the below code the problem is demonstrated, line 65 will cause a segmentation fault. 1 #include <iostream>
2
1865
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 my process many objects(of a class A) are being created( about 500).
4
4237
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 actually point to the element that is being erased." I design/implemented a observer pattern that is priority based. It so happened that observers were deregistering themselves while they were being notified. In other words, we were iterating...
6
3948
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 number of words in the input, and to count how many times each word occurred.
75
3559
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; char ch; long int a=0;
0
10435
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10163
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9037
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.