Iteration with cycling and clamping.
I have some code which cycles through items in a list as the user presses buttons. I need to be able to move forward and backwards through this list and apply a filtering predicate. For lists that cycle through the available items when operator++ is called on the last iterator before end that satisfies the predicate it the iterator should point to the first element that satisfies the predicate. When operator-- is called on that iterator it should point to the last iterator before end again. For lists that traverse the available items without cycling when operator++ is called on the last iterator before end that satisfies the predicate the iterator should point to the same element. When operator-- is called on the first iterator that satisfies the predicate the iterator should point to the same element. The logic isn't very hard but I'd rather not duplicate it. Are there any available iterator adaptors that perform these operations at the range limits? Thanks, Michael Marcin
Michael Marcin wrote:
For lists that cycle through the available items when operator++ is called on the last iterator before end that satisfies the predicate it the iterator should point to the first element that satisfies the predicate. When operator-- is called on that iterator it should point to the last iterator before end again.
See: http://tinyurl.com/2o3ch4 or: http://tinyurl.com/2bgjfv Then you might want to apply boost::filter_iterator.
For lists that traverse the available items without cycling when operator++ is called on the last iterator before end that satisfies the predicate the iterator should point to the same element. When operator-- is called on the first iterator that satisfies the predicate the iterator should point to the same element.
I haven't ever seen such one, AFAIK. Regards, -- Shunsuke Sogame
participants (2)
-
Michael Marcin
-
shunsuke