Let's say I have an unordered_map:
std::unordered_map<Key, BigObject> big_objects;
where BigObject is like:
struct BigObject {
BigObject(P1, P2, P3); // <--- expensive
/*...*/
};
and I have a Key k, and a set of arguments for BigObjects constructor P1 p1, P2 p2 and P3 p3.
If big_objects already contains k I want to do nothing. If big_objects does not contain K I want to construct and insert BigObject(p1,p2,p3)
Is it possible to do this with a single lookup on big_objects?
ie Will emplace or try_emplace construct BigObject if the key is already present?
Update
After some testing it seems like emplace does construct BigObject but try_emplace doesn't ?
ie
big_objects[k] = BigObject(p1,p2,p3) // insert k, k now present...
big_objects.emplace(k, p1, p2, p3); // does construct a BigObject
big_objects.try_emplace(k, p1, p2, p3); // does not construct a BigObject
Is this correct?