std::search_n
De cppreference.com
|
|
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. |
<metanoindex/>
<tbody> </tbody>| Déclaré dans l'en-tête <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, BinaryPredicate p ); |
(2) | |
Recherches
[first, last) la plage pour la première séquence de comptage des éléments identiques, chacune égale à la valeur valeur donnée. La première version utilise operator== de comparer les éléments, la deuxième version utilise le prédicat binaire donné p .Original:
Searches the range
[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.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Paramètres
| first, last | - | l'éventail des éléments à examiner
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 | - | la longueur de la séquence à rechercher
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 | - | la valeur des éléments à rechercher
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 |
| Type requirements | ||
-ForwardIt must meet the requirements of ForwardIterator.
| ||
Retourne la valeur
Iiterator au début de la séquence trouvée dans la gamme
[first, last). Si aucune séquence n'est trouvée, last est retourné .Original:
Iiterator to the beginning of the found sequence in the range
[first, last). If no such sequence is found, last is returned.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Complexité
À la plupart des applications
last - first du prédicat .Original:
At most
last - first applications of the predicate.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Mise en œuvre possible
| 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;
}
|
Exemple
| This section is incomplete |
Voir aussi
trouve la dernière séquence d'éléments dans une certaine plage 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. (fonction générique) | |
(C++11) |
trouve le premier élément répondant à des critères spécifiques 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. (fonction générique) |
recherches pour une série d'éléments Original: searches for a range of elements The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction générique) | |