I want a cycled_view iterator to an element of a list that I found using ranges::find. I think, a solution should look something like this:
std::list<int> li{1, 2, 3};
auto find_2 = ranges::find(li, 2);
auto cycle_list = li | ranges::views::cycle;
decltype(cycle_list)::iterator (find_2); // it doesn't work like this
I cannot search cycle_list directly, because it doesn't terminate, if the element cannot be found.
An alternative would be to search li for the element and only search cycle_list for the element, if it was found in li, but this seems inefficient.
Is there a proper solution to this problem using ranges?
std::list<int> li{1, 2, 3};
auto cycle_list = li | ranges::views::cycle | ranges::views::take(li.size());
auto ret = ranges::find(cycle_list,2).base();
I want a cycled_view iterator to an element of a list that I found using
ranges::find
. I think, a solution should look something like this:I cannot search
cycle_list
directly, because it doesn't terminate, if the element cannot be found. An alternative would be to searchli
for the element and only searchcycle_list
for the element, if it was found inli
, but this seems inefficient.Is there a proper solution to this problem using ranges?
Thanks in advance