Question about return value of STD MAP::INSERT
-
Hi I am looking at the documentation for map::insert std::map<Key,T,Compare,Allocator>::insert - cppreference.com[^] seems that when you use two parameters such a key and value it returns a iterator to the inserted or the element that prevented listed below is my code
procpointer->extsymcollector->insert(pair{exsympointer->SYMESDID, *exsympointer });
my code does NOT complie unless I specfify a return value of a pair iterator and bool and the following
std::pair::iterator, bool> ret;
ret = procpointer->extsymcollector->insert(pair{exsympointer->SYMESDID, *exsympointer });dont understand why ?
-
Hi I am looking at the documentation for map::insert std::map<Key,T,Compare,Allocator>::insert - cppreference.com[^] seems that when you use two parameters such a key and value it returns a iterator to the inserted or the element that prevented listed below is my code
procpointer->extsymcollector->insert(pair{exsympointer->SYMESDID, *exsympointer });
my code does NOT complie unless I specfify a return value of a pair iterator and bool and the following
std::pair::iterator, bool> ret;
ret = procpointer->extsymcollector->insert(pair{exsympointer->SYMESDID, *exsympointer });dont understand why ?
You can simplify to:
auto ret = procpointer->extsymcollector->insert({exsympointer->SYMESDID, *exsympointer})
ForNow wrote:
my code does NOT complie
What compiler to you use? what message to you get?
Mircea
-
You can simplify to:
auto ret = procpointer->extsymcollector->insert({exsympointer->SYMESDID, *exsympointer})
ForNow wrote:
my code does NOT complie
What compiler to you use? what message to you get?
Mircea
-
You can simplify to:
auto ret = procpointer->extsymcollector->insert({exsympointer->SYMESDID, *exsympointer})
ForNow wrote:
my code does NOT complie
What compiler to you use? what message to you get?
Mircea
-
when I specify a return of a iterator I get no suitable conversion
map ::iterator extsymiter;
extsympointer = procpointer->extsymcollector->insert({exsympointer->SYMESDID, * exsympointer });
std::map::insert
returns a pair. Nothing you can do about that. Your code should look like:map ::iterator extsymiter;
auto ret = procpointer->extsymcollector->insert({exsympointer->SYMESDID, * exsympointer });
if (ret.second)
extsymiter = ret.first;
else
//map already had an element with same keyIf you don't care if the element was there or not, you can just skip the
if
.Mircea
-
You can simplify to:
auto ret = procpointer->extsymcollector->insert({exsympointer->SYMESDID, *exsympointer})
ForNow wrote:
my code does NOT complie
What compiler to you use? what message to you get?
Mircea