Friday, September 1, 2017

C++11: Algorithms: iota

The function iota stores an increasing value in each element in a container. Here is an example:

#include <numeric>
#include <iostream>

int main()
{
  int myArray[5];

  int * beginIter = &myArray[0];
  int * endIter   = &myArray[5];

  std::iota(beginIter, endIter, 7);

  std::cout << myArray[0] << " " << 
               myArray[1] << " " <<
               myArray[2] << " " << std::endl;
  return 0;
}
// Output: 7 8 9
Reference: https://isocpp.org/wiki/faq/cpp11-library-stl#cpp11-algorithms

No comments:

Post a Comment