std::search_n - cppreference.com
Da cppreference.com.
|
|
Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate. La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
<metanoindex/>
<tbody> </tbody>
| Elemento definito nell'header <algorithm> |
||
|
|
(1) | |
|
|
(2) | |
Ricerche la [first, last) gamma per la prima sequenza di conteggio elementi identici, ciascuno pari al valore determinato valore. La prima versione utilizza operator== di confrontare gli elementi, la seconda versione utilizza il predicato binario dato 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.
Parametri
| first, last | - | la gamma di elementi da esaminare Original: the range of elements to examine The text has been machine-translated via Google Translate. |
| count | - | la lunghezza della sequenza di ricerca Original: the length of the sequence to search for The text has been machine-translated via Google Translate. |
| value | - | il valore degli elementi da ricercare Original: the value of the elements to search for The text has been machine-translated via Google Translate. |
| 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.
| ||
Valore di ritorno
Iiterator all'inizio della sequenza trovato [first, last) gamma. In assenza di tale sequenza viene trovato, viene restituito last.
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.
Complessità
Alla maggior parte delle applicazioni last - first del predicato.
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.
Possibile implementazione
| 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; } |
Esempio
Vedi anche
trova l'ultima sequenza di elementi di un certo intervallo Original: finds the last sequence of elements in a certain range The text has been machine-translated via Google Translate. (funzione di modello) [modifica] | |
(C++11) |
trova il primo elemento che soddisfi i criteri specifici Original: finds the first element satisfying specific criteria The text has been machine-translated via Google Translate. (funzione di modello) [modifica] |
| searches for a range of elements (funzione di modello) [modifica] | |