Sdílet prostřednictvím


iota

Obsahuje počáteční hodnotu, počínaje první prvek a zaplnění postupné přírůstky hodnoty (_Value++) v jednotlivých prvků v intervalu [_First, _Last).

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

Parametry

  • _First
    Vstupní iterátor, který řeší první prvek v rozsahu, který má být obsazeno.

  • _Last
    Vstupní iterátor, který řeší poslední prvek v rozsahu, který má být obsazeno.

  • _Value
    Počáteční hodnota pro uložení v prvním prvku a postupně krok pro další prvky.

Příklad

Následující příklad ukazuje použití některých iota funkce vyplněním seznam celá čísla a následné plnění vector s list tak, aby random_shuffle funkce může být použita.

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

Výsledek

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

Požadavky

Záhlaví:<numerická>

Obor názvů: std

Viz také

Referenční dokumentace

Standardní knihovna šablon