Hi,
I've checked out various documentation for multimap but can't
find anywhere it explicitly stated that insert() invalidates multimap
iterators.
consider this pseudo code:-
int DataItem::genDe rived ()
{
DataItem::Multi Map::const_iter ator iter =
dataItems.lower _bound(paramete rReference);
DataItem::Multi Map::const_iter ator end =
dataItems.upper _bound(paramete rReference);
while (iter != end)
{
newItem = calcNewItem (iter);
dataItems.inser t (newItem);
}
}
It selects a particular value in the mm and finds the lower and
upper bounds on their location. It then loops on all of them
calculating a derived value for each. This is inserted into the
same mm. A bad idea?
--
Nick Keighley 4 4497
Nick Keighley wrote: I've checked out various documentation for multimap but can't find anywhere it explicitly stated that insert() invalidates multimap iterators.
You did not find that statement because it it is false. The standard says
about associative containers [23.1.2/8]:
The insert members shall not affect the validity of iterators and
references to the container, and the erase members shall invalidate
only iterators and references to the erased elements.
Best
Kai-Uwe Bux
Nick Keighley wrote: Hi,
I've checked out various documentation for multimap but can't find anywhere it explicitly stated that insert() invalidates multimap iterators.
consider this pseudo code:-
int DataItem::genDe rived () { DataItem::Multi Map::const_iter ator iter = dataItems.lower _bound(paramete rReference); DataItem::Multi Map::const_iter ator end = dataItems.upper _bound(paramete rReference);
while (iter != end) { newItem = calcNewItem (iter); dataItems.inser t (newItem); } }
It selects a particular value in the mm and finds the lower and upper bounds on their location. It then loops on all of them calculating a derived value for each. This is inserted into the same mm. A bad idea?
From SGI:
"Multimap has the important property that inserting a new element into a
multimap does not invalidate iterators that point to existing elements.
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 prefer not to suppose that, because if I change the container, I must
change my code too, but you can assume iterators are not invalidated
after an insert if you prefer.
Kai-Uwe Bux wrote: Nick Keighley wrote:
I've checked out various documentation for multimap but can't find anywhere it explicitly stated that insert() invalidates multimap iterators.
You did not find that statement because it it is false. The standard says about associative containers [23.1.2/8]:
The insert members shall not affect the validity of iterators and references to the container, and the erase members shall invalidate only iterators and references to the erased elements.
thanks.
Ok so the iterator isn't invalid, but back to my pseudo code:-
DataItem::Multi Map::const_iter ator iter =
dataItems.lower _bound(paramete rReference);
DataItem::Multi Map::const_iter ator end =
dataItems.upper _bound(paramete rReference);
while (iter != end)
{
newItem = calcNewItem (iter);
dataItems.inser t (newItem);
iter++;
}
could you end up processing items more than once? There's
something that seems to be doing that (there's a lot of code so isn't
definitely the mm calls at fault).
--
Nick Keighley
Nick Keighley wrote: Kai-Uwe Bux wrote:
Nick Keighley wrote: Ok so the iterator isn't invalid, but back to my pseudo code:-
DataItem::Multi Map::const_iter ator iter = dataItems.lower _bound(paramete rReference); DataItem::Multi Map::const_iter ator end = dataItems.upper _bound(paramete rReference);
while (iter != end) { newItem = calcNewItem (iter); dataItems.inser t (newItem); iter++; }
could you end up processing items more than once? There's something that seems to be doing that (there's a lot of code so isn't definitely the mm calls at fault).
I'm not familiar to multimap, but I suppose that depending on the
position of the new element inserted, you could access it too, and
calculate a new item from that item calculated previously.
I suppose what you want to do is iterate through the original elements
of the container, not through the original and the new elements, but
only you know what you want to do. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kenneth Massey |
last post by:
Is the following code guaranteed to work? I have a hashed set of pointers,
which I would like to selectively delete from. Can I iterate through the
set, deleting certain ones, without invalidating the iterator? This
ominous statement in the STL "set" documentation makes me worried. I saw
no similar statement on the "hash_multiset" docs.
"Erasing an element from a set also does not invalidate any iterators,
except, of course, for...
|
by: Dennis Jones |
last post by:
Hi,
Is there a way to iterate through a multimap in such a way as to encounter
only the unique keys? In other words, since a multimap allows duplicate
keys, I would like to iterate through the entire multimap, and if a
particular key has duplicates, only see one of them. I don't think I care
about which of the duplicate entries I see, because once I have an entry, I
can use lower_bound and upper_bound to iterate through them, right? ...
|
by: francois.chartrand |
last post by:
Hi,
I would like to know if there is a way to locate a specific pair in a
multimap ?
Example:
std::multimap<int,int> myMap;
std::multimap<int,int>::iterator myMapIterator;
|
by: Steve Edwards |
last post by:
Hi,
While iterating through a multimap, I need to replace elements that meet
certain conditions with a new element.
There doesm't seem to be a replace() function for multimaps, so I'm
inserting a new element, and then deleting the old.
typedef multimap<double, MyStructType, greater<double> >;MyMultimap
MyMultimap map = ...
|
by: srikpen |
last post by:
I am unable to get the "is" I keep getting the below:
the find : this
the find : this
what I want is:
the find : this
the find : is
| |
by: reppisch |
last post by:
Hi Ng,
I have a multiset for keeping elements sorted in a container but key
values may also be equal.
Is there any guaranteed traversal order within the duplicate keys of a
multimap?
When inserting duplicate keys to the multiset i need output order to be
in insert order.
|
by: Saile |
last post by:
I want to give an array the values from the specific multimap's key's values.
multimap<string,int> mymultimap;
multimap<string,int>::iterator it;
pair<multimap<string,int>::iterator,multimap<string,int>::iterator> ret;
mymultimap.insert (pair<string,int>("test",10));
mymultimap.insert (pair<string,int>("test",20));
mymultimap.insert (pair<string,int>("ab",100));
mymultimap.insert (pair<string,int>("ab",200));
|
by: ambarish.mitra |
last post by:
Hi all,
I have a multimap, where key is an int and the value is a class. I can
insert into the multimap, but finding it difficult to retrieve the
value when keys match. I can do this with primitive types (int/char
etc).
Example:
class A {
|
by: Nikhil.S.Ketkar |
last post by:
Hi,
How does the == operator for multimap in STL behave ? I was under the
impression that this is supposed to properly compare multimaps for
equality. It seems that what it actually does is just check if each
member in location L in one multimap is equal to the the member in
location L in the other multimap. The documentation on
http://www.sgi.com/tech/stl/Multimap.html says "Tests two multimaps
for equality. This is a global function,...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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...
| |
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |