Reputation: 249
I am currently implementing an iterator for an internal data structure and had a look at how QVector implements its iterator. I don't understand why the QTypedArrayData::iterator implements its ++ and -- operators like:
T *i;
inline iterator &operator++() { ++i; return *this; }
inline iterator &operator--() { i--; return *this; }
What I don't understand is the discrepancy between the two: Why does it use a postfix decrement operator?
Thanks for any clarification!
Upvotes: 1
Views: 94
Reputation: 98425
Your lack of understanding implies an expectation that there is any practical difference between the two, and, that the coding was purposefully done that way. Such expectation is reasonable, but incorrect. You can write these operations either way, and they'll work just the same. It might matter on non-POD types that are expensive to copy/move, but that's not the case here. And it used to matter 15-20 years ago on the poor compilers of that era. Thankfully we don't have to deal with VS6 anymore :)
Upvotes: 2