The Wayback Machine - https://web.archive.org/web/20180207115452/http://es.cppreference.com:80/w/cpp/algorithm/generate_n
Espacios de nombres
Variantes
Acciones

std::generate_n

De cppreference.com
< cpp‎ | algorithm

 
 
Algoritmo biblioteca
Funciones
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Para no modificar la secuencia de las operaciones
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.
Modificación de la secuencia de operaciones
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.
Particionamiento operaciones
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.
Clasificación de las operaciones (en rangos ordenados)
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.
Las operaciones binarias de búsqueda (en rangos ordenados)
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.
Conjunto de operaciones (en rangos ordenados)
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.
Operaciones del montón
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.
Mínimo / máximo de operaciones
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.
Operaciones numéricas
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 biblioteca
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.
 
Defined in header <algorithm>
template<class OutputIt, class Size, class Generator >

void generate_n( OutputIt first, Size count, Generator g );
template<class OutputIt, class Size, class Generator >

OutputIt generate_n( OutputIt first, Size count, Generator g );
(hasta C++11)

(desde C++11)
Asigna valores, generados por g dado objeto de función, a los elementos count primero en el comienzo rango en first, si count>0. No hace nada por lo demás .
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.

Contenido

[editar]Parámetros

first -
el comienzo de la gama de elementos a generar
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 -
número de los elementos a generar
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:

Ret fun();

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

Type requirements
-
OutputIt must meet the requirements of OutputIterator.

[editar]Valor de retorno

(Ninguno) (hasta C++11)
Original:
(none) (hasta C++11)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Iterator un más allá del último elemento asignado si count>0, first lo contrario. (desde C++11)
Original:
Iterator one past the last element assigned if count>0, first otherwise. (desde C++11)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar]Complejidad

Exactamente count invocaciones de g() y asignaciones, para 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.

[editar]Posible implementación

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;}

[editar]Ejemplo

El siguiente código rellena una matriz de enteros con números aleatorios .
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.

#include <cstddef>#include <cstdlib>#include <iostream>#include <iterator>#include <algorithm>   int main(){conststd::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

[editar]Ver también

asigna un valor a una serie de elementos
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.

(función de plantilla)[edit]
guarda el resultado de una función en un intervalo
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.

(función de plantilla)[edit]
close