Skip to content

Instantly share code, notes, and snippets.

@mochow13
Created September 18, 2018 15:23
Show Gist options
  • Save mochow13/9310ab92a885321e79ca44f5f2591277 to your computer and use it in GitHub Desktop.
Save mochow13/9310ab92a885321e79ca44f5f2591277 to your computer and use it in GitHub Desktop.
std::vector<int> collection={6,5,3,2,1,4,6,7};
std::vector<int> sums, mults;
// contains the partial sum of collection in result
std::partial_sum(begin(collection), end(collection), std::back_inserter(sums));
// contains the partial product
std::partial_sum(begin(collection), end(collection), std::back_inserter(mults), std::multiplies<int>());
// you can also use your own binary operation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment