std::iota
De cppreference.com
![]() |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
Defined in header <numeric>
|
||
template< class ForwardIterator, class T > void iota( ForwardIterator first, ForwardIterator last, T value ); |
(ya que C + +11) | |
Rellena el
[first, last)
rango con valores crecientes de forma secuencial, comenzando con value
y repetitiva evaluar ++value .Original:
Fills the range
[first, last)
with sequentially increasing values, starting with value
and repetitively evaluating ++value.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.
Equivalente operación:
Original:
Equivalent operation:
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.
*(d_first) = value; *(d_first+1) = ++value; *(d_first+2) = ++value; *(d_first+3) = ++value; ...
Contenido |
[editar] Parámetros
first, last | - | el intervalo de elementos de suma
Original: the range of elements to sum The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
value | - | valor inicial a la tienda, la expresión + valor + debe estar bien formado
Original: initial value to store, the expression ++value must be well-formed The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[editar] Valor de retorno
(Ninguno)
Original:
(none)
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.
[editar] Complejidad
Exactamente
last - first
incrementos y asignaciones .Original:
Exactly
last - first
increments and assignments.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.
[editar] Posible implementación
template<class ForwardIterator, class T> void iota(ForwardIterator first, ForwardIterator last, T value) { while(first != last) { *first++ = value; ++value; } } |
[editar] Ejemplo
El siguiente ejemplo se aplica a un vector std::random_shuffle de los iteradores para una std::list desde std::random_shuffle no se puede aplicar a un std::list directamente. std::iota se utiliza para crear el vector .
Original:
The following example applies std::random_shuffle to a vector of iterators to a std::list since std::random_shuffle cannot be applied to an std::list directly. std::iota is used to create the vector.
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 <numeric> #include <algorithm> #include <list> #include <vector> #include <iostream> int main() { std::list<int> l(10); std::iota(l.begin(), l.end(), -4); std::vector<std::list<int>::iterator> v(l.size()); std::iota(v.begin(), v.end(), l.begin()); std::random_shuffle(v.begin(), v.end()); std::cout << "Contents of the list: "; for(auto n: l) { std::cout << n << ' '; } std::cout << '\n'; std::cout << "Contents of the list, shuffled: "; for(auto i: v) { std::cout << *i << ' '; } std::cout << '\n'; }
Output:
Contents of the list: -4 -3 -2 -1 0 1 2 3 4 5 Contents of the list, shuffled: 0 -1 3 4 -4 1 -2 -3 2 5
[editar] Ver también
asigna una serie de elementos de un cierto valor 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. (función de plantilla) | |
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) |