For std::set both the associated types iterator and const_iterator are constant bidirectional iterators. The reason for this is because std::set ordered. If you changed the set element, although an iterator, you would break this ordering.
Consider a std::set with ordered elements {1, 4, 8} . If you then did something like *set.insert(5).first = 10; (if it was allowed), first 5 will be inserted to get {1, 4, 5, 8} , and then the inserted element will be set to 10 to get {1, 4, 10, 8} . Now the ordering invariant has been broken.
Since you insert 5 with insert(5) , there is no reason to dereference the iterator and assign it 5 .
Joseph mansfield
source share