从范围末尾开始搜索 [英] start search from end of range
问题描述
我想知道是否可以从范围的末尾而不是开头开始 std::search()
.我知道 find_end
就足够了,但我想特别知道 search
是否可行.一个例子:
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:
我有一个数据集<代码>1 2 3 4 5 1 2 |3 4 5 6 7 1 3 其中|
代表范围中断,这两个分区将异步执行.
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.
是否可以从分区的最后一个点开始搜索范围1 2
?我认为可以对范围和子序列进行某种反向迭代器吗?
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)
推荐答案
标准算法 std::find_end
是专门为只有前向迭代器的容器编写的.例如,您可以将 std::find_end
与 std::forward_list
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
当然,您可以将 std::search
与双向迭代器一起使用,或者应用迭代器适配器 std::reverse_iterator
或使用容器的内置反向迭代器,例如例如 std::vector 类的反向迭代器,您可以在其中使用成员函数 rbegin
和 rend
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
这篇关于从范围末尾开始搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!