Espaces de noms
Variantes
Affichages
Actions

std::generate

De cppreference.com
< cpp‎ | algorithm

 
 
Bibliothèque 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 séquence des opérations
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 séquence des opérations
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 opérations 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.
Opérations de tri (sur les gammes triés)
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
Opérations binaires de recherche (sur les gammes triés)
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.
Définir les opérations (sur les gammes triés)
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.
Opérations 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.
Opérations numériques
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.
Bibliothèque 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.
 
Déclaré dans l'en-tête <algorithm>
template< class ForwardIt, class Generator >
void generate( ForwardIt first, ForwardIt last, Generator g );
Attribue à chaque élément dans la plage [first, last) une valeur générée par l'objet de fonction donnée g .
Original:
Assigns each element in range [first, last) a value generated by the given function object g.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Sommaire

[modifier] Paramètres

first, last -
l'ensemble d'éléments à générer
Original:
the range of elements to generate
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
g - generator function object that will be called.

The signature of the function should be equivalent to the following:

Ret fun();

The type  Ret must be such that an object of type ForwardIt can be dereferenced and assigned a value of type  Ret. ​

Type requirements
-
ForwardIt must meet the requirements of ForwardIterator.

[modifier] Retourne la valeur

(Aucun)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[modifier] Complexité

Exactement std::distance(first, last) invocations de g() et les affectations .
Original:
Exactly std::distance(first, last) invocations of g() and assignments.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[modifier] Mise en œuvre possible

template<class ForwardIt, class Generator>
void generate(ForwardIt first, ForwardIt last, Generator g)
{
    while (first != last) {
        *first++ = g();
    }
}

[modifier] Exemple

Les usages code suivant remplit un vecteur de nombres aléatoires:
Original:
The following code uses fills a vector with random numbers:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <algorithm>
#include <iostream>
#include <cstdlib>
 
int main()
{
    std::vector<int> v(5);
    std::generate(v.begin(), v.end(), std::rand); // Using the C function rand()
 
    std::cout << "v: ";
    for (auto iv: v) {
        std::cout << iv << " ";
    }
    std::cout << "\n";
}

Résultat :

v: 52894 15984720 41513563 41346135 51451456

[modifier] Voir aussi

attribue un ensemble d'éléments d'une certaine valeur
Original:
assigns a range of elements a certain value
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) [edit]
enregistre le résultat de l'application de N d'une fonction
Original:
saves the result of N applications of a function
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) [edit]