std::experimental::ranges::search_n
From cppreference.com
< cpp | experimental | ranges
| Defined in header <experimental/ranges/algorithm> |
||
| template< ForwardIterator I, Sentinel<I> S, class T, class Pred = ranges::equal_to<>, class Proj = ranges::identity > |
(1) | (ranges TS) |
| template< ForwardRange R, class T, class Pred = ranges::equal_to<>, class Proj = ranges::identity > |
(2) | (ranges TS) |
1) 範囲
[first, last)において、指定された値valueと、述語predに従ってそれぞれ等しい要素のシーケンスをcount個探します。目次 |
[編集] パラメータ
| first, last | - | 調査する要素の範囲 |
| r | - | 調査する要素の範囲 |
| count | - | 検索するシーケンスの長さ |
| value | - | 検索する値 |
| pred | - | 投影された要素とvalueを比較する述語 |
| proj | - | 要素に適用される射影 |
[編集] 返り値
範囲[first, last)で見つかったシーケンスの先頭を指すイテレータ。そのようなシーケンスが見つからなかった場合は、lastと等価なイテレータが返されます。
[編集] 計算量
述語と射影の適用回数は最大でlast - first回です。
[編集] 実装例
template<ForwardIterator I, Sentinel<I> S, class T, class Pred = ranges::equal_to<>, class Proj = ranges::identity> requires IndirectlyComparable<I, const T*, Pred, Proj> I search_n(I first, S last, ranges::difference_type_t<I> count, const T& value, Pred pred = Pred{}, Proj proj = Proj{}) { for (; first != last; ++first) { if (!ranges::invoke(pred, ranges::invoke(proj, *first), value)) continue; I candidate = first; ranges::difference_type_t<I> cur_count = 0; while (true) { ++cur_count; if (cur_count == count) // success return candidate; ++first; if (first == last) // exhausted the list return first; if (!ranges::invoke(pred, ranges::invoke(proj, *first), value)) // too few in a row break; } } return first; } |
[編集] 例
| このセクションは未完成です 理由: 例がありません |
[編集] 関連項目
| 範囲内である要素が連続して出現する最初の箇所を検索する (関数テンプレート) | |
| 特定の範囲内で最後の要素のシーケンスを見つける (function template) | |
| 特定の基準を満たす最初の要素を見つける (function template) | |
| 要素の範囲を検索します。 (function template) |