I almost never put a ++ or -- anywhere except on its own line. I know they can lead to undefined behavior and can be hell for debugging. But for verbosity purposes, I'm tempted. Is this valid code?
map<int, int> dict;
...
int key = ...;
if (dict.lower_bound(key) != dict.begin()) {
int prevval = (--dict.lower_bound(key))->second;
...
}
I'd like to just do
int prevval = (dict.lower_bound(key)-1)->second;
but bidirectional iterators don't have operator-()
defined.
Thanks!