Skip to content

Instantly share code, notes, and snippets.

@mochow13
Created September 15, 2018 05:05
Show Gist options
  • Save mochow13/b937f9067861c54cfb3d0d732784a138 to your computer and use it in GitHub Desktop.
Save mochow13/b937f9067861c54cfb3d0d732784a138 to your computer and use it in GitHub Desktop.
std::vector<int> collection={1,2,0,5,0,3,4};
int counter=0;
// notice that we are capturing counter by reference
std::generate(begin(collection), end(collection), [&]() {
return counter++;
});
// collection gets replaced by values starting from 0
// modified collection = {0,1,2,3,4,5,6}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment