سؤال

lets say I want to go through container in a circular way:

idx = 0, idx =1 .. idx = size()-1, idx =0, idx =1 ...

Is there a way to do in with std or boost? I know that algorithms operate on ranges not on containers so I guess Im out of luck, but I just wanted to check.

P.S. No need for manual implementations, it is trivial(if you dont forget about seq points :P ), just

curr_idx= (curr_idx+1) % my_cont.size()
هل كانت مفيدة؟

المحلول

I am not aware of any function like that, but this answer shows how to use Boost.Iterator to create an iterator adaptor that cycles over a collection.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top