Freigeben über


iota

Speichert einen Startwert, beginnt mit dem ersten und füllt mit aufeinander folgenden Schritten dieses Werts (_Value++) in dem Elemente im Intervall [_First, _Last) aus.

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

Parameter

  • _First
    Ein Eingabeiterator, der das erste Element im zu füllenden Bereich behandelt.

  • _Last
    Ein Eingabeiterator, der das letzte Element im zu füllenden Bereich behandelt.

  • _Value
    Der im ersten Element zu speichern und Anfangswert, für nachfolgende Elemente nacheinander zu erhöhen.

Beispiel

Im folgenden Beispiel werden einige Verwendungen für die iota-Funktion, indem sie Liste von Ganzzahlen ausfüllt und dann Vektor mit list ein, damit die random_shuffle-Funktion verwendet werden kann.

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

Ausgabe

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

Anforderungen

Header: <numerisch>

Namespace: std

Siehe auch

Referenz

Standardvorlagenbibliothek