std::search_n
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Defined in header <algorithm>
|
||
| template< class ForwardIt, class Size, class T > ForwardIt1 search_n( ForwardIt first, ForwardIt last, Size count, const T& value ); |
(1) | |
| template< class ForwardIt, class Size, class T, class BinaryPredicate > ForwardIt1 search_n( ForwardIt first, ForwardIt last, Size count, const T& value, |
(2) | |
[first, last)。的第一个版本使用operator==比较的元素,第二个版本使用给定的二元谓词p.[first, last) for the first sequence of count identical elements, each equal to the given value value. The first version uses operator== to compare the elements, the second version uses the given binary predicate p.You can help to correct and verify the translation. Click here for instructions.
目录 |
[编辑] 参数
| first, last | - | 检查的元素
Original: the range of elements to examine The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |||||||||
| count | - | 序列的长度,以搜寻
Original: the length of the sequence to search for The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |||||||||
| value | - | 的元素的值,以搜寻
Original: the value of the elements to search for The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |||||||||
| p | - | binary predicate which returns true if the elements should be treated as equal. The signature of the predicate function should be equivalent to the following:
The signature does not need to have const &, but the function must not modify the objects passed to it. | |||||||||
| Type requirements | |||||||||||
-ForwardIt must meet the requirements of ForwardIterator.
| |||||||||||
[编辑] 返回值
[first, last)找到的序列的开头。如果没有发现这样的序列,last返回.[first, last). If no such sequence is found, last is returned.You can help to correct and verify the translation. Click here for instructions.
[编辑] 复杂性
last - first的谓词中的应用.last - first applications of the predicate.You can help to correct and verify the translation. Click here for instructions.
[编辑] 可能的实现
| First version |
|---|
template<class ForwardIt, class Size, class T> ForwardIt1 search_n(ForwardIt first, ForwardIt last, Size count, const T& value) { Size curr_count = 0; ForwardIt result, t_last = first; std::advance(t_last, std::distance(first, last) - count + 1); for (; first != t_last; first++) { curr_count = 0; result = first; while (*first == value) { curr_count++; if (curr_count == count) { return result; } ++first; } } return last; } |
| Second version |
template<class ForwardIt, class Size, class T, class BinaryPredicate> ForwardIt1 search_n(ForwardIt first, ForwardIt last, Size count, const T& value, BinaryPredicate p) { Size curr_count = 0; ForwardIt result, t_last = first; std::advance(t_last, std::distance(first, last) - count + 1); for (; first != t_last; first++) { curr_count = 0; result = first; while (p(*first == value)) { curr_count++; if (curr_count == count) { return result; } ++first; } } return last; } |
[编辑] 为例
| 本节是不完整的 |
[编辑] 另请参阅
| 发现在一定范围内的最后一个序列中的元素 Original: finds the last sequence of elements in a certain range The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (函数模板) | |
| (C++11) |
找到的第一个元素,满足特定的标准 Original: finds the first element satisfying specific criteria The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (函数模板) |
| searches for a range of elements (函数模板) | |