Working on clang-tidy check that is finding modifications of container you are iterating I found this lines of code. Here, we are using operator on std::map. In this case is not a problem, because we use the key of actual entry and it will not break anything, but we can easily remove operator by binding for-loop variable by reference.
All of the const changes can be separate and submitted. (Please do so before posting revised patch to simplify review.)
Sink variable to use please.
Also, assigning to reference is mildly confusing. Can you add a comment to clarify?
This appears to be changing behaviour. The State variable previous survive to end of scope unmodified and is now modified part way through before hitting more conditional code. Please revert.