std::generate
|
|
Esta página se ha traducido por ordenador/computador/computadora de la versión en inglés de la Wiki usando Google Translate.
La traducción puede contener errores y palabras aparatosas/incorrectas. Planea sobre el texto para ver la versión original. Puedes ayudar a corregir los errores y mejorar la traducción. Para instrucciones haz clic aquí. |
| Definido en el archivo de encabezado <algorithm>
|
||
| template< class ForwardIt, class Generator > void generate( ForwardIt first, ForwardIt last, Generator g ); |
||
[first, last) un valor generado por el objeto función dada g . [first, last) a value generated by the given function object g. You can help to correct and verify the translation. Click here for instructions.
Contenido |
[editar] Parámetros
| first, last | - | la gama de elementos a generar
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:
El tipo Ret debe ser tal que un objeto de tipo ForwardIt puede ser desreferenciado y asignado un valor de tipo Ret. | ||||||
| Requerimientos de tipo | ||||||||
-ForwardIt debe reunir los requerimientos de ForwardIterator.
| ||||||||
[editar] Valor de retorno
You can help to correct and verify the translation. Click here for instructions.
[editar] Complejidad
g() y tareas .g() and assignments.You can help to correct and verify the translation. Click here for instructions.
[editar] Posible implementación
template<class ForwardIt, class Generator> void generate(ForwardIt first, ForwardIt last, Generator g) { while (first != last) { *first++ = g(); } } |
[editar] Ejemplo
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"; }
Salida:
v: 52894 15984720 41513563 41346135 51451456
[editar] Ver también
| Asigna un cierto valor a una serie de elementos (plantilla de función) | |
| guarda el resultado de las aplicaciones de N de una función 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. (plantilla de función) |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
