共用方式為


iota

從第一個項目和填滿儲存開始值,用該值 (_Value++) 的後續增加開始在每一個項目在間隔 [_First, _Last)

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

參數

  • _First
    說明要填滿的範圍的第一個項目的輸入 Iterator。

  • _Last
    說明要填滿的範圍的最後一個項目的輸入 Iterator。

  • _Value
    儲存在第一個項目和循序增加的起始值為後續的項目。

範例

下列範例會藉由填入整數 清單 然後填入 向量 示範 iota 函式的用法是 list ,以便可以使用 random_shuffle 函式。

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

Output

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

需求

標題: <的值>

命名空間: std

請參閱

參考

標準樣板程式庫