» 4 months ago, # |   +31 std::set is red-black tree (not guaranteed but I don't know any other implementation). So iterator in set belongs to node in tree. Node contains item. When you do smth like s.erase(it) node in tree is delete. it is invalid iterator. So any operation with it is meaningless and UB. But one can guess that node deleting is just mark that memory used by node is free and rebalance tree. So if memory under it not changed then it undestandable that *it returned 3. And there can be that --it returned 2 (node must contain ptr to parent node). But again — don't do UB and don't guess why UB code do something.