For some reason I am iterating over elements of a class in an std::set and would like to slightly modify the keys, knowing that the order will be unchanged.
std::set
Another option is to const_cast to a reference type :
const_cast
class Foo { public: void incrementB() const { ++ const_cast< int& >( b_ ); } private: int b_; };
But as sehe already said, you shouldn't modify set's elements.