Compartilhar via


iota

Armazena um valor inicial, começando com o primeiro elemento e preencher com sucessivas incrementos de esse valor (_Value++) em cada um dos elementos no intervalo [_First, _Last).

template<class ForwardIterator, class Type>
   void iota(
      ForwardIterator _First, 
      ForwardIterator _Last,
      Type _Value 
   );

Parâmetros

  • _First
    Um iterador de entrada atende o primeiro elemento no intervalo para ser preenchido.

  • _Last
    Um iterador de entrada atende o último elemento no intervalo para ser preenchido.

  • _Value
    O valor inicial para armazenar no primeiro elemento e a incrementar em sucessão para elementos subseqüentes.

Exemplo

O exemplo a seguir demonstra alguns usos da função de iota preenchendo lista de inteiros e então preenchendo vetor com list de modo que a função de random_shuffle pode ser usada.

// compile by using: cl /EHsc /nologo /W4 /MTd
#include <algorithm>
#include <numeric>
#include <list>
#include <vector>
#include <iostream>

using namespace std;

int main(void)
{
    list <int> intList(10);
    vector <list<int>::iterator> intVec(intList.size());

    // Fill the list
    iota(intList.begin(), intList.end(), 0);

    // Fill the vector with the list so we can shuffle it
    iota(intVec.begin(), intVec.end(), intList.begin());

    random_shuffle(intVec.begin(), intVec.end());

    // Output results
    cout << "Contents of the integer list: " << endl;
    for (auto i: intList) {
        cout << i << ' ';
    }
    cout << endl << endl;

    cout << "Contents of the integer list, shuffled by using a vector: " << endl;
    for (auto i: intVec) {
        cout << *i << ' ';
    }
    cout << endl;
}

Saída

Contents of the integer list:

0 1 2 3 4 5 6 7 8 9

Contents of the integer list, shuffled by using a vector:

8 1 9 2 0 5 7 3 4 6

Requisitos

Cabeçalho: <numeric>

namespace: STD

Consulte também

Referência

Standard Template Library