Wednesday, April 29, 2020

Generating sequentially increasing values in C++

Say you need to generate a sequence, in C++, simply consisting of the first so many integers, like, 1,2,3,4,5.

With a little programming experience, you can come up with a dozen different ways to do this, but here's an obscure one:

std::list<int> l(5);
std::iota(l.begin(), l.end(), 1);


According to CppReference, the function is named after the integer function ⍳ from the programming language APL.

The more you know.




No comments:

Post a Comment

Note: Only a member of this blog may post a comment.