Reputation: 9809
struct Instrument
{
std::string make;
std::string brand;
double age;
Instrument(std::string const& f, std::string const& s, double l) { BLABLA }
bool operator<(Instrumentconst& rhs) { return BLABLABLA;}
};
std::map<int,Instrument> instMap;
Instrument myObj();
instMap.insert(pair<int,Instrument>(10,myObj));
If I need to update a value in this map for individual attributes separately. Would we be creating copies of Instrument every time we retrieve it from map to update it?
it = instMap.lower_bound(10);
if (it != m.end())
*(it->second).brand = "Jonas";<= will there be a copy of Instrument object created here?
Is this the most memory(and time) efficient way to update values - if this operation had to be done on a million entries?
We are using C++ 98.
Upvotes: 2
Views: 128
Reputation: 17117
The simple answer is no, the Instrument object will not be copied.
The std::string
will be copied, at least in c++98.
Upvotes: 3