reverse-iterator

What's the difference between a reversed tuple and a reversed list?

帅比萌擦擦* 提交于 2019-11-30 17:19:40
Reversing a tuple and reversing a list returns objects of different type: >>> reversed((1,2)) <reversed at 0x7fffe802f748> >>> reversed([1,2]) <list_reverseiterator at 0x7fffebdd4400> They have the same dir . Neither type is a subclass of the other. Why is that? What can one do that the other can't? jsbueno Basically, a list implements the __reversed__ method and returns an specialized object, while tuple falls back to the default implementation of reversed for any sequence: >>> list.__reversed__ <method '__reversed__' of 'list' objects> >>> tuple.__reversed__ AttributeError: type object

Why does removing the _first_ element of a list invalidate `.rend()`?

落爺英雄遲暮 提交于 2019-11-29 02:04:05
Tested on Mac OS X using XCode 4.6. This example code shows removing the last element of an std::list works as I expected: an iterator reference to list::end() is still "1 past the end" and is still valid, even through removal of the last element . But the second example counters my intuition. Removing the first element of the list changes list::rend() , which I thought was "1 past the beginning". Was my expectation wrong? Why was it wrong? Why does your reference to "1 past the end" through deletion of the last element remain valid (should it not?), but a reference to "1 in front of the

Why does removing the _first_ element of a list invalidate `.rend()`?

倖福魔咒の 提交于 2019-11-27 16:20:45
问题 Tested on Mac OS X using XCode 4.6. This example code shows removing the last element of an std::list works as I expected: an iterator reference to list::end() is still "1 past the end" and is still valid, even through removal of the last element . But the second example counters my intuition. Removing the first element of the list changes list::rend() , which I thought was "1 past the beginning". Was my expectation wrong? Why was it wrong? Why does your reference to "1 past the end" through

Reference invalidation after applying reverse_iterator on a custom made iterator

旧城冷巷雨未停 提交于 2019-11-26 23:29:15
问题 I implemented a bidirectional iterator, however instead of operating on a data structure, it returns a mathematical series which one can iteratively calculate through in both directions. In fact, I'm iterating through the integers, using ++ and -- on an int. This means that the data is not stored in a different structure, and hence when the iterator goes out of scope, so does the value. Nevertheless, I would expect the next code (minimal failing example) sample to work, as the iterator stays