当前位置: 动力学知识库 > 问答 > 编程问答 >

c++ - start search from end of range

问题描述:

I'm wondering if it is possible to start a std::search() from the end of the range as opposed to the beginning. I know find_end would be sufficient, but I would like to specifically know if this is possible with search. An example:

I have a data set

1 2 3 4 5 1 2 | 3 4 5 6 7 1 3 where the | represents a break in the range, these two partitions will be executed asynchronously.

Is it possible to search for the range 1 2 starting from the last point in the partition? I would think it would be possible to do some sort of reverse iterator on both the range and the subsequence?

search(reverse_iter_begin, reverse_iter_end, reverse_iter_subseq_begin, reverse_iter_subseq_end)

网友答案:

Standard algorithm std::find_end is specially written for containers that have only a forward iterator. For example you can use std::find_end with std::forward_list

Of course you may use std::search with bidirectional iterators either applying iterator adapter std::reverse_iterator or uing a built-in reverse iterator of a container as for example the reverse iterator of class std::vector where you can use member functions rbegin and rend

分享给朋友:
您可能感兴趣的文章:
随机阅读: