The most obvious answer: which of them has the semantics that you want? They visit the objects in a different order.
Generally, if there are no other considerations, people expect ascending, and this is what you should use when visiting sites. In C ++ it is much more idiomatic to use iterators for this. Normal iterators are visited in ascending order, reverse iterators in descending order. If you clearly don't need to go down, you should use regular iterators. This is what people expect, and when you use reverse iterators, the first thing the reader asks is why. In addition, I did not measure it, but it would not surprise me if ordinary iterators were faster than iterators on the contrary. In Java, iterators are also idiomatic, and you don't have reverse iterators.
If I need a decreasing order when visiting, I will use a while loop (unless I have reverse iterators that do this for me); I'm something like:
int index = numberOfElements; while ( index != 0 ) { -- index; // ... }
much more readable (and easier to get right) than any of the alternatives.
If you do not visit objects, but simply think that descending seems more natural to me: the control variable contains the number of times left. And since the account is never used as an index, there is no problem that it will be one of the indices, and you can use the traditional for .
for ( int count = numberOfTimes; count != 0; -- count ) {
But it really is a matter of style; I have seen many upstream cycles for this as well.
source share