Is the following way of manipulating a string or a container idiomatic?
string s = "hello";
for (auto &p : s) {
p = somefunction(p); // somefunction without side effects
}
This implies iterating over a range while changing the contained elements. The container is not modified in its layout so the iterators should be valid during the iteration.
The same effect could of course easily "be coded" differently, but I am interested in if this is the idiomatic way of doing it?
I asked a similar question earlier, but that was related to the case where the container's layout is being modified, and here the answer is: iterate over a copy of the container. C++ idiomatic way of iterating over a container that itself is being modified