I have a std::map that I would like to insert an object into, but I would like to avoid unnecessary copies, since it is a large object, and copies take time.
I tried this:
MyPODType data(otherData);
data.modify();
myMap["Some key"] = data;
However this requires 2 copies: one to copy the otherData, and one in the assignment operator to insert the object. Since it's POD, the copy constructor and assignment operator are both the default.
How can I do this with only 1 copy? I realize some compilers will optimize out the second copy but I'd like to do this in a portable way.
myMap.emplace("Some key", otherData).first->second.modify();emplacelooks like it's exactly what I need.