Suppose I have a backtracking algorithm where I need to remove an element from a map, do something, then put it back. I am not sure if there is a good way to do it:
func(std::<K, V> map &dict) { for (auto i : dict) { remove i from dict; func(dict); put i back to dict; } } I know there are ways to delete an element from map in here but I am not sure if there are ways to achieve what I described above. I am aware that I can create a new dict in for loop and pass it in func but I am wondering if it can be done using the same dict.
remove i from dict;step will invalidate the iterator your range-for is holding under the hood.stackofpairs?funcis using your map...