Throwing exception when the same key inserted into std::map
I use VS2010 and I noticed when I add a key:value pair into std::map,if
the similar key is already in the map, then the insertion is ignored.So
for example:
std::string pipeName = "pipe1";
_pipes.insert(std::make_pair(pipeName,ppl));
_pipes.insert(std::make_pair(pipeName,ppl));
This operation results in only one pair stored in the map.I would like to
throw an exception in such a case.So yes,I can just compare before the
insertion if the key already exists, but can std::map be forced to throw
it?
No comments:
Post a Comment