std::experimental::ranges::search
定義於標頭檔案 <experimental/ranges/algorithm> |
||
template< ForwardIterator I1, Sentinel<I1> S1, ForwardIterator I2, Sentinel<I2> S2, class Pred = ranges::equal_to<>, |
(1) | (ranges TS) |
template< ForwardRange R1, ForwardRange R2, class Pred = ranges::equal_to<>, class Proj1 = ranges::identity, class Proj2 = ranges::identity > |
(2) | (ranges TS) |
[
first1,
last1)
中搜索序列 [
first2,
last2)
的第一次出現。元素在分別被 proj2 和 proj1 投影后,使用 pred 進行比較。儘管上述宣告所示,演算法宣告的實際模板引數數量和順序未指定。因此,如果在呼叫演算法時使用顯式模板引數,程式可能不可移植。
目錄 |
[編輯] 引數
first1, last1 | - | 要檢查的元素範圍 |
r1 | - | 要檢查的元素範圍 |
first2, last2 | - | 要搜尋的元素範圍 |
r2 | - | 要搜尋的元素範圍 |
pred | - | 應用於投影元素的謂詞 |
proj1 | - | 應用於第一個範圍元素的投影。 |
proj2 | - | 應用於第二個範圍元素的投影。 |
[編輯] 返回值
指向範圍 [
first1,
last1)
中序列 [
first2,
last2)
首次出現起始位置的迭代器。如果 [
first2,
last2)
為空,則返回 first1。如果未找到此類出現,則返回一個與 last1 相等的迭代器。
[編輯] 複雜度
至多 S * N
次謂詞和各投影的應用,其中 S = last2 - first2 且 N = last1 - first1。
[編輯] 可能的實現
template<ForwardIterator I1, Sentinel<I1> S1, ForwardIterator I2, Sentinel<I2> S2, class Pred = ranges::equal_to<>, class Proj1 = ranges::identity, class Proj2 = ranges::identity> requires IndirectlyComparable<I1, I2, Pred, Proj1, Proj2> I1 search(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = Pred{}, Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{}) { for (; ; ++first1) { I1 it = first1; for (I2 it2 = first2; ; (void)++it, (void)++it2) { if (it2 == last2) return first1; if (it == last1) return it; if (!ranges::invoke(pred, ranges::invoke(proj1, *it), ranges::invoke(proj2, *it2))) break; } } } |
[編輯] 示例
本節不完整 原因:無示例 |
[編輯] 參閱
搜尋一個範圍的元素首次出現的位置 (函式模板) | |
在特定範圍中尋找最後一次出現的元素序列 (函式模板) | |
如果一個集合是另一個集合的子集,則返回 true (函式模板) | |
判斷兩組元素是否相同 (函式模板) | |
尋找第一個滿足特定條件的元素 (函式模板) | |
如果一個範圍在字典上小於另一個範圍,則返回 true (函式模板) | |
尋找兩個範圍開始不同的第一個位置 (函式模板) | |
在範圍中搜索元素的連續複製 (函式模板) |