Espaços nominais
Variantes
Acções

std::iota

Da cppreference.com
< cpp‎ | algorithm

 
 
Biblioteca algoritmo
Funções
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Não modificar operações de seqüência
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.
Modificando operações de seqüência
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.
Particionamento operações
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.
Operações de classificação (em intervalos 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.
Binários operações de busca (em intervalos 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.
Definir operações (em intervalos 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.
Operações de pilha
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 operações
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.
Operações 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 <numeric>
template< class ForwardIterator, class T >
void iota( ForwardIterator first, ForwardIterator last, T value );
(a partir do C++ 11)
Preenche a [first, last) intervalo com valores crescentes sequencialmente, começando com value e repetidamente avaliar ++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.
Operação equivalente:
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.
*(d_first)   = value;
*(d_first+1) = ++value;
*(d_first+2) = ++value;
*(d_first+3) = ++value;
...

Índice

[editar] Parâmetros

first, last -
a gama de elementos a soma
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 para a loja, a expressão + + valor deve ser bem 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

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

[editar] Complexidade

Exatamente last - first incrementos e atribuições.
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.

[editar] Possível implementação

template<class ForwardIterator, class T>
void iota(ForwardIterator first, ForwardIterator last, T value)
{
    while(first != last) {
        *first++ = value;
        ++value;
    }
}

[editar] Exemplo

O exemplo que se segue aplica-se a um vector std::random_shuffle de iteradores para um std::list desde std::random_shuffle não pode ser aplicado directamente a uma std::list. std::iota é usada para criar o 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.

#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] Veja também

atribui um intervalo de elementos de um certo 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.

(modelo de função) [edit]
guarda o resultado de uma função em um 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.

(modelo de função) [edit]