Search code examples
c++coding-styleiteratorprefixdecrement

C++ Iterator dereference and prefix increment/decrement style? Is *--Iter ok style wise?


In coding with C++ iterators if you wanted to get the previous value to what an iterator points to would you write:

*--Iter

or would you think it better to add parentheses like so:

*(--Iter)

?


Solution

  • It doesn't matter as far as program correctness is concerned. But I always express this as *(--Iter) because this is more self-documenting and easier to understand to human beings than *--Iter.