Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would std::unordered_map::emplace() fail?

I have a std::unordered_map that I emplace() an object to via:

my_map.emplace(std::piecewise_construct,
               std::forward_as_tuple(key),
               std::forward_as_tuple(value1, value2));

This fails at some point during runtime with a false in the second position of the returned tuple. Is there a way to get more information about what's going on? top doesn't show any trouble with memory.

like image 759
chrisaycock Avatar asked Jul 22 '26 15:07

chrisaycock


1 Answers

A false in .second means "equivalent element already present." In such case, the iterator in .first points to that equivalent element.

So what's happening is that you already have key in the map, and you can use .first on the return value to access it.

like image 67
Angew is no longer proud of SO Avatar answered Jul 25 '26 08:07

Angew is no longer proud of SO