If I change an element of an std::set, for example, through an iterator, I know it is not “reinserted” or “resorted”, but is there any mention of if it triggers undefined behavior? For example, I would imagine insertions would screw up. Is there any mention of specifically what happens?
Share
You should not edit the values stored in the set directly. I copied this from MSDN documentation which is somewhat authoritative:
Why this is is pretty easy to understand. The
setimplementation will have no way of knowing you have modified the value behind its back. The normal implementation is a red-black tree. Having changed the value, the position in the tree for that instance will be wrong. You would expect to see all manner of wrong behaviour, such asexistsqueries returning the wrong result on account of the search going down the wrong branch of the tree.