Skip to content

Instantly share code, notes, and snippets.

@scraimer
Created February 12, 2017 08:29
Show Gist options
  • Save scraimer/df9f13cd8312a70d2147823b0b480551 to your computer and use it in GitHub Desktop.
Save scraimer/df9f13cd8312a70d2147823b0b480551 to your computer and use it in GitHub Desktop.
Showing that std::acuumulate is just as good as a for loop on
#include <numeric>
#include <iterator>
int vals[5] = {1, 2, 3, 4, 5};
int main()
{
// Force the array into a const (just because I don't want to iterate on modifiable cells
auto const & b = vals;
int sum = std::accumulate(std::begin(b), std::end(b), 0);
return sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment