std::experimental::ranges::find, std::experimental::ranges::find_if, std::experimental::ranges::find_if_not
來自 cppreference.com
< cpp | experimental | ranges
定義於標頭檔案 <experimental/ranges/algorithm> |
||
template< InputIterator I, Sentinel<I> S, class T, class Proj = ranges::identity > requires IndirectRelation<ranges::equal_to<>, projected<I, Proj>, const T*> |
(1) | (範圍 TS) |
template< InputRange R, class T, class Proj = ranges::identity > requires IndirectRelation<ranges::equal_to<>, |
(2) | (範圍 TS) |
template< InputIterator I, Sentinel<I> S, class Proj = ranges::identity, IndirectUnaryPredicate<projected<I, Proj>> Pred > |
(3) | (範圍 TS) |
template< InputRange R, class Proj = ranges::identity, IndirectUnaryPredicate<projected<ranges::iterator_t<R>, Proj>> Pred > |
(4) | (範圍 TS) |
template< InputIterator I, Sentinel<I> S, class Proj = ranges::identity, IndirectUnaryPredicate<projected<I, Proj>> Pred > |
(5) | (範圍 TS) |
template< InputRange R, class Proj = ranges::identity, IndirectUnaryPredicate<projected<ranges::iterator_t<R>, Proj>> Pred > |
(6) | (範圍 TS) |
返回範圍 [
first,
last)
中滿足特定條件的第一個元素
儘管上述宣告所示,演算法宣告的實際模板引數數量和順序未指定。因此,如果在呼叫演算法時使用顯式模板引數,程式可能不可移植。
目錄 |
[編輯] 引數
first, last | - | 要檢查的元素範圍 |
r | - | 要檢查的元素範圍 |
value | - | 用於比較投影元素的值 |
pred | - | 應用於投影元素的謂詞 |
proj | - | 應用於元素的投影 |
[編輯] 返回值
指向滿足條件的第一個元素的迭代器。如果沒有找到這樣的元素,則返回一個與 last 比較相等的迭代器。
[編輯] 複雜度
謂詞和投影至多應用 last - first 次。
[編輯] 可能實現
第一版 |
---|
template<InputIterator I, Sentinel<I> S, class T, class Proj = ranges::identity> requires IndirectRelation<ranges::equal_to<>, projected<I, Proj>, const T*> I find(I first, S last, const T& value, Proj proj = Proj{}) { for (; first != last; ++first) if (ranges::invoke(proj, *first) == value) break; return first; } |
第二版 |
template<InputIterator I, Sentinel<I> S, class Proj = ranges::identity, IndirectUnaryPredicate<projected<I, Proj>> Pred> I find_if(I first, S last, Pred pred, Proj proj = Proj{}) { for (; first != last; ++first) if (ranges::invoke(pred, ranges::invoke(proj, *first))) break; return first; } |
第三版 |
template<InputIterator I, Sentinel<I> S, class Proj = ranges::identity, IndirectUnaryPredicate<projected<I, Proj>> Pred> I find_if_not(I first, S last, Pred pred, Proj proj = Proj{}) { for (; first != last; ++first) if (!ranges::invoke(pred, ranges::invoke(proj, *first))) break; return first; } |
[編輯] 示例
本節不完整 原因:無示例 |
[編輯] 參閱
(C++11) |
尋找第一個滿足特定條件的元素 (函式模板) |
尋找第一對相等的(或滿足給定謂詞的)相鄰項 (函式模板) | |
在特定範圍中尋找最後一次出現的元素序列 (函式模板) | |
搜尋一組元素中的任何一個 (函式模板) | |
尋找兩個範圍開始不同的第一個位置 (函式模板) | |
搜尋元素範圍 (函式模板) |