An interesting tidbit of info I discovered recently was that std::for_each does not actually return the value object of the <key, value> map pair. I had assumed (/laugh) that it did, similar to how, say, a vector’s object is passed to you to do something with. In other words, I assumed it sent only the value of the map pair. As you might expect by now, though, it returns a pair object of the same type stored in the map. So if you’re working on the value part, you would use the object.second syntax and, likewise, object.first for playing around with the keys.
1 August 2010