[ Web Proxy ]
URL:
Viewing: https://fr.cppreference.com/cpp/algorithm/find [Back]  [Original]

std::find, std::find_if, std::find_if_not cppreference.com
cppreference.com
Espaces de noms
Variantes

std::find, std::find_if, std::find_if_not

De cppreference.com


 
 
Bibliothque d'algorithmes
Fonctions
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Non-modification de la squence des oprations
Original:
Non-modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Modification de la squence des oprations
Original:
Modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Des oprations de partitionnement
Original:
Partitioning operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Oprations de tri (sur les gammes tris)
Original:
Sorting operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
is_sorted (C++11)
is_sorted_until (C++11)
sort
Oprations binaires de recherche (sur les gammes tris)
Original:
Binary search operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Dfinir les oprations (sur les gammes tris)
Original:
Set operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Oprations Heap
Original:
Heap operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Minimum / maximum de fonctionnement
Original:
Minimum/maximum operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Oprations numriques
Original:
Numeric operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Bibliothque C
Original:
C library
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
<tbody> </tbody>
Dclar dans l'en-tte <algorithm>
template< class InputIt, class T > InputIt find( InputIt first, InputIt last, const T& value );
(1)
template< class InputIt, class UnaryPredicate > InputIt find_if( InputIt first, InputIt last, UnaryPredicate p );
(2)
template< class InputIt, class UnaryPredicate > InputIt find_if_not( InputIt first, InputIt last, UnaryPredicate q );
(3) (depuis C++11)
Ces fonctions trouver le premier lment de la [first, last) gamme qui rpond des critres spcifiques:
Original:
These functions find the first element in the range [first, last) that satisfies specific criteria:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
1. find recherches pour un lment gal value
Original:
1. find searches for an element equal to value
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2. find_if recherches pour un lment pour lequel prdicat retourne p true
Original:
2. find_if searches for an element for which predicate p returns true
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
3. find_if_not recherches pour lment pour lequel prdicat retourne q false
Original:
3. find_if_not searches for element for which predicate q returns false
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Paramtres

first, last -
l'ventail des lments 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.
value -
valeur comparer les lments d'
Original:
value to compare the elements to
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
p - prdicat unaire qui retourne true
pour l'lment requis
Original:
for the required element
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
.

L'expression p(v) doit pouvoir tre convertie bool pour tout argument v de type (possiblement const) VT, o VT est le type de valeur de InputIt, inconditionellement de value category, et ne doit pas modifier v. Ainsi, un type-paramtre VT&n'est pas permis ainsi que pour VT sauf pour VT un dplacement est quivalent une copie (depuis C++11).

q - prdicat unaire qui retourne false
pour l'lment requis
Original:
for the required element
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
.

L'expression q(v) doit pouvoir tre convertie bool pour tout argument v de type (possiblement const) VT, o VT est le type de valeur de InputIt, inconditionellement de value category, et ne doit pas modifier v. Ainsi, un type-paramtre VT&n'est pas permis ainsi que pour VT sauf pour VT un dplacement est quivalent une copie (depuis C++11).

Type requirements
-
InputIt must meet the requirements of InputIterator.

Retourne la valeur

Itrateur sur le premier lment satisfaisant la condition ou last si aucun lment correspondant n'est trouv .
Original:
Iterator to the first element satisfying the condition or last if no such element is found.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Complexit

Tout au plus last - first applications du prdicat
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.

Mise en uvre possible

First version
template<class InputIt, class T>
InputIt find(InputIt first, InputIt last, const T& value)
{
    for (; first != last; ++first) {
        if (*first == value) {
            return first;
        }
    }
    return last;
}
Second version
template<class InputIt, class UnaryPredicate>
InputIt find_if(InputIt first, InputIt last, UnaryPredicate p)
{
    for (; first != last; ++first) {
        if (p(*first)) {
            return first;
        }
    }
    return last;
}
Third version
template<class InputIt, class UnaryPredicate>
InputIt find_if_not(InputIt first, InputIt last, UnaryPredicate q)
{
    for (; first != last; ++first) {
        if (!q(*first)) {
            return first;
        }
    }
    return last;
}
Si vous n'avez pas de C++11, un quivalent de std::find_if_not est d'utiliser std::find_if avec le prdicat ni .
Original:
If you do not have C++11, an equivalent to std::find_if_not is to use std::find_if with the negated predicate.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
template<class InputIt, class UnaryPredicate>
InputIt find_if_not(InputIt first, InputIt last, UnaryPredicate q)
{
    return std::find_if(first, last, std::not1(q));
}

Exemple

L'exemple suivant recherche un entier dans un vecteur d'entiers .
Original:
The following example finds an integer in a vector of integers.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <iostream>
#include <algorithm>
#include <vector>

int main()
{
    int n1 = 3;
    int n2 = 5;
 
    std::vector<int> v{0, 1, 2, 3, 4};
 
    auto result1 = std::find(v.begin(), v.end(), n1);
    auto result2 = std::find(v.begin(), v.end(), n2);
 
    if (result1 != v.end()) {
        std::cout << "v contains: " << n1 << '\n';
    } else {
        std::cout << "v does not contain: " << n1 << '\n';
    }

    if (result2 != v.end()) {
        std::cout << "v contains: " << n2 << '\n';
    } else {
        std::cout << "v does not contain: " << n2 << '\n';
    }
}

Rsultat :

v contains: 3
v does not contain: 5

Voir aussi

trouve deux identiques (ou une autre relation) des lments adjacents les uns aux autres
Original:
finds two identical (or some other relationship) items adjacent to each other
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction gnrique) [edit]
trouve la dernire squence d'lments 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 gnrique) [edit]
searches for any one of a set of elements
(fonction gnrique) [edit]
trouve la premire position dans laquelle deux plages diffrentes
Original:
finds the first position where two ranges differ
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction gnrique) [edit]
recherches pour une srie d'lments
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 gnrique) [edit]

Web Proxy Viewer  |  New URL  |  Original Page