Created
February 12, 2017 08:29
-
-
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
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 <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