Last active
September 9, 2018 13:18
-
-
Save lichray/64674ef6c4d57b5245be to your computer and use it in GitHub Desktop.
generate_n is a better iota_n.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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