std::generate_n
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. | 
| Defined in header <algorithm>
  | ||
| template< class OutputIt, class Size, class Generator > void generate_n( OutputIt first, Size count, Generator g ); | (C fino + 11) (dal C++11) | |
Assegna valori, generati da 
g data funzione oggetto, agli elementi count primi all'inizio gamma a first, se count>0. Non fa niente altrimenti.Original:
Assigns values, generated by given function object 
g, to the first count elements in the range beginning at first, if count>0. Does nothing otherwise.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.
| Indice | 
[modifica] Parametri
| first | - |  l'inizio dell'intervallo di elementi da generare Original:  the beginning of 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. | |||||||||
| count | - |  numero di elementi da generare Original:  number of the 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: 
 The type Ret must be such that an object of type OutputIt can be dereferenced and assigned a value of type Ret.  | |||||||||
| Type requirements | |||||||||||
| - OutputItmust meet the requirements ofOutputIterator. | |||||||||||
[modifica] Valore di ritorno
(Nessuno) (C fino + 11)
Original:
(none) (C fino + 11)
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.
Iterator un passato l'ultimo elemento assegnato se 
count>0, first altrimenti. (dal C++11)Original:
Iterator one past the last element assigned if 
count>0, first otherwise. (dal C++11)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.
[modifica] Complessità
Esattamente 
count invocazioni di g() e le assegnazioni, per count>0.Original:
Exactly 
count invocations of g() and assignments, for count>0.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.
[modifica] Possibile implementazione
| template< class OutputIt, class Size, class Generator > OutputIt generate_n( OutputIt first, Size count, Generator g ) { for( Size i = 0; i < count; i++ ) { *first++ = g(); } return first; } | 
[modifica] Esempio
 Il codice seguente riempie un array di interi con numeri casuali . 
 
Original:
 The following code fills an array of integers 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.
You can help to correct and verify the translation. Click here for instructions.
#include <cstddef> #include <cstdlib> #include <iostream> #include <iterator> #include <algorithm> int main() { const std::size_t N = 5; int ar[N]; std::generate_n(ar, N, std::rand); // Using the C function rand() std::cout << "ar: "; std::copy(ar, ar+N, std::ostream_iterator<int>(std::cout, " ")); std::cout << "\n"; }
Output:
52894 15984720 41513563 41346135 51451456
[modifica] Vedi anche
|  assegna un valore a un numero di elementi  Original:  assigns a value to a number of elements  The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (funzione di modello) | |
|  salva il risultato di una funzione in un intervallo  Original:  saves the result of a function in a range  The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (funzione di modello) | |


