Namensräume
Varianten
Aktionen

std::generate

Aus cppreference.com
< cpp‎ | algorithm

 
 
Algorithm Bibliothek
Funktionen
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Nicht-modifizierende Sequenz Operationen
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.
Modifizierende Sequenz Operationen
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.
Partitionierungsoperationen
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.
Sortierung Operationen (auf sortierten Bereiche)
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.
Binary Suchaktionen (auf sortierten Bereiche)
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.
Set-Operationen (auf sortierten Bereiche)
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.
Heap-Operationen
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 Operationen
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.
Numerische Operationen
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.
C-Bibliothek
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.
 
definiert in Header <algorithm>
template< class ForwardIt, class Generator >
void generate( ForwardIt first, ForwardIt last, Generator g );
Weist jedes Element im Bereich [first, last) ein Wert der gegebenen Funktion Objekt generiert 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.

Inhaltsverzeichnis

[Bearbeiten] Parameter

first, last -
der Bereich der Elemente zu erzeugen
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.

[Bearbeiten] Rückgabewert

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

[Bearbeiten] Komplexität

Genau std::distance(first, last) Anrufungen g() und Aufgaben .
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.

[Bearbeiten] Mögliche Implementierung

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

[Bearbeiten] Beispiel

Der folgende Code verwendet füllt einen Vektor mit Zufallszahlen:
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";
}

Output:

v: 52894 15984720 41513563 41346135 51451456

[Bearbeiten] Siehe auch

weist eine Reihe von Elementen ein bestimmter Wert
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.

(Funktions-Template) [edit]
speichert das Ergebnis der N-Anwendungen einer Funktion
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.

(Funktions-Template) [edit]