Skip to content

Instantly share code, notes, and snippets.

@lichray lichray/iota_n.cc
Last active Sep 9, 2018

Embed
What would you like to do?
generate_n is a better iota_n.
#include <algorithm>
#include <vector>
#include <iterator>
#include <iostream>
int main()
{
std::vector<int> v;
// instead of asking for iota_n(std::back_inserter(v), 10, 1);
std::generate_n(back_inserter(v), 10, [n = 0]() mutable { return ++n; });
for (auto i : v)
std::cout << i << ' ';
std::cout << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.